local extension = Package:new("sifu_heg_ld")
extension.extensionName = "sifu_heg"

local U = require "packages/utility/utility"
local H = require "packages/ol_hegemony/util"
extension.game_modes_whitelist = {"zhonger_heg_mode"}

Fk:loadTranslationTable{
  ["sifu_heg_ld"] = "君临天下",
  ["zhonger_ld_heg"] = "君临",
  ["zhonger_lord_heg"] = "君主",
}

local dengai = General(extension, "zhonger_ld_heg__dengai", "wei", 4)
dengai.mainMaxHpAdjustedValue = -1
dengai:addSkill("ld__tuntian")
dengai:addSkill("ld__jixi")
dengai:addSkill("ziliang")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__dengai"] = "邓艾",
  ["#zhonger_ld_heg__dengai"] = "矫然的壮士",
  ["designer:zhonger_ld_heg__dengai"] = "官方",
  ["illustrator:zhonger_ld_heg__dengai"] = "Amo",
  ["~zhonger_ld_heg__dengai"] = "君不知臣，臣不知君。罢了……罢了！",
}

local caohong = General(extension, "zhonger_ld_heg__caohong", "wei", 4)
local ldhuyuan_active = fk.CreateActiveSkill{
  name = "#ldhuyuan_active",
  mute = true,
  card_num = 1,
  target_num = 1,
  interaction = function()
    return UI.ComboBox {choices = {"zeld__huyuan_give", "zeld__huyuan_equip"}}
  end,
  card_filter = function(self, to_select, selected, targets)
    if #selected == 0 then
      if self.interaction.data == "zeld__huyuan_give" then
        return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
      elseif self.interaction.data == "zeld__huyuan_equip" then
        return Fk:getCardById(to_select).type == Card.TypeEquip
      end
    end
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected == 0 and #selected_cards == 1 then
      if self.interaction.data == "zeld__huyuan_give" then
        return to_select ~= Self.id
      elseif self.interaction.data == "zeld__huyuan_equip" then
        return Fk:currentRoom():getPlayerById(to_select):hasEmptyEquipSlot(Fk:getCardById(selected_cards[1]).sub_type)
      end
    end
  end,
}
local ldhuyuan = fk.CreateTriggerSkill{
  name = "ldhuyuan",
  anim_type = "defensive",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Finish and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
   local success, dat = player.room:askForUseActiveSkill(player, "#ldhuyuan_active", "#ldhuyuan-invoke", true)
    if success then
      self.cost_data = dat
      return true
    end
end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local dat = self.cost_data
    local choice = dat.interaction
    if choice == "zeld__huyuan_give" then
      room:obtainCard(dat.targets[1], dat.cards, false, fk.ReasonGive, player.id)
    elseif choice == "zeld__huyuan_equip" then
      room:moveCardTo(dat.cards, Card.PlayerEquip, room:getPlayerById(dat.targets[1]), fk.ReasonPut, self.name, nil, true, player.id)
      if not player.dead then
        local targets = table.map(table.filter(room.alive_players, function(p)
          return #p:getCardIds("ej") > 0 end), Util.IdMapper)
        local to2 = room:askForChoosePlayers(player, targets, 1, 1, "#ldhuyuan_discard-choose", self.name, true, true)
        if #to2 > 0 then
        local cid = room:askForCardChosen(player, room:getPlayerById(to2[1]), "ej", self.name)
        room:throwCard({cid}, self.name, room:getPlayerById(to2[1]), player)
        end
      end
    end
  end,
}
local heyi = H.CreateArraySummonSkill{
  name = "hs__heyi",
  array_type = "formation",
}
local heyiTrig = fk.CreateTriggerSkill{ -- FIXME
  name = '#hs__heyi_trigger',
  visible = false,
  frequency = Skill.Compulsory,
  refresh_events = {fk.TurnStart, fk.GeneralRevealed, fk.EventAcquireSkill, "fk.RemoveStateChanged", fk.EventLoseSkill, fk.GeneralHidden, fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then return data == heyi
    elseif event == fk.GeneralHidden then return player == target
    else return player:hasShownSkill(self.name, true, true) end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      local ret = #room.alive_players > 3 and player:hasSkill(self) and H.inFormationRelation(p, player)
      room:handleAddLoseSkills(p, ret and 'hs__feiying' or "-hs__feiying", nil, false, true)
    end
  end,
}
heyi:addRelatedSkill(heyiTrig)
local feiying = fk.CreateDistanceSkill{
  name = "hs__feiying",
  correct_func = function(self, from, to)
    if to:hasSkill(self) then
      return 1
    end
    return 0
  end,
}
Fk:addSkill(feiying)
ldhuyuan:addRelatedSkill(ldhuyuan_active)
caohong:addSkill(ldhuyuan)
caohong:addSkill(heyi)
caohong:addCompanions("zhonger_st_heg__caoren")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__caohong"] = "曹洪",
  ["#zhonger_ld_heg__caohong"] = "魏之福将",
  ["designer:zhonger_ld_heg__caohong"] = "官方",
  ["illustrator:zhonger_ld_heg__caohong"] = "官方",
  ["ldhuyuan"] = "护援",
  [":ldhuyuan"] = "结束阶段，你可选择：1.将一张非装备牌交给一名角色；2.将一张装备牌置入一名角色的装备区，然后你可以弃置场上的一张牌。",
  ["#ldhuyuan_active"] = "护援",
  ["#ldhuyuan-invoke"] = "护援：选择一项发动",
  ["#ldhuyuan_discard-choose"] = "护援：你可以弃置场上的一张牌",
  ["zeld__huyuan_give"] = "给出手牌",
  ["zeld__huyuan_equip"] = "置入装备",

  ["hs__heyi"] = "鹤翼",
  [":hs__heyi"] = "阵法技，与你处于同一队列的角色拥有〖飞影〗。",
  ["hs__feiying"] = "飞影",
  [":hs__feiying"] = "锁定技，其他角色计算与你的距离+1。",
  ["$ldhuyuan1"] = "拼将性命，也要保将军周全。",
  ["$ldhuyuan2"] = "舍命献马，护我曹公！",
  ["cv:zhonger_ld_heg__caohong"] = "官方",
  ["~zhonger_ld_heg__caohong"] = "福兮祸所伏……",
}

local jiangwei = General(extension, "zhonger_ld_heg__jiangwei", "shu", 4)
jiangwei.deputyMaxHpAdjustedValue = -1
jiangwei:addSkill("tiaoxin")
jiangwei:addSkill("yizhi")
jiangwei:addSkill("tianfu")
jiangwei:addRelatedSkill("ld__guanxing")
jiangwei:addRelatedSkill("ld__kanpo")
jiangwei:addCompanions("zhonger_st_heg__zhugeliang")
Fk:loadTranslationTable{
  ["$tiaoxin_zhonger_ld_heg__jiangwei1"] = "小小娃娃，乳臭未干。",
  ["$tiaoxin_zhonger_ld_heg__jiangwei2"] = "快滚回去，叫你主将出来！",
  ["zhonger_ld_heg__jiangwei"] = "姜维",
  ["#zhonger_ld_heg__jiangwei"] = "龙的衣钵",
  ["designer:zhonger_ld_heg__jiangwei"] = "官方",
  ["~zhonger_ld_heg__jiangwei"] = "臣等正欲死战，陛下何故先降……",
}

local jiangfei = General(extension, "zhonger_ld_heg__jiangwanfeiyi", "shu", 3)
jiangfei:addSkill("ld__shengxi")
jiangfei:addSkill("shoucheng")
jiangfei:addCompanions("zhonger_st_heg__zhugeliang")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__jiangwanfeiyi"] = "蒋琬费祎",
  ["#zhonger_ld_heg__jiangwanfeiyi"] = "社稷股肱",
  ["designer:zhonger_ld_heg__jiangwanfeiyi"] = "淬毒",
  ["illustrator:zhonger_ld_heg__jiangwanfeiyi"] = "cometrue",
  ["~zhonger_ld_heg__jiangwanfeiyi"] = "墨守成规，终为其害啊……",
}

local xusheng = General(extension, "zhonger_ld_heg__xusheng", "wu", 4)
local yicheng = fk.CreateTriggerSkill{
  name = "ld__yicheng",
  anim_type = "defensive",
  events = {fk.TargetConfirmed,fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if event ==fk.CardUsing then
      --使用杀时触发
      return player:hasSkill(self) and data.card.trueName=="slash" and H.compareKingdomWith(target, player) 
      and (event == fk.TargetConfirmed or data.firstTarget) and not target.dead
    end
    --被杀时触发
    return player:hasSkill(self) and H.compareKingdomWith(target, player) and data.card.trueName == "slash" 
    and (event == fk.TargetConfirmed or data.firstTarget) and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#ld__yicheng-ask::" .. target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    target:drawCards(1, self.name)
    if not target.dead then
      room:askForDiscard(target, 1, 1, true, self.name, false)
    end
  end
}
xusheng:addSkill(yicheng)
xusheng:addCompanions("zhonger_st_heg__dingfeng")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__xusheng"] = "徐盛",
  ["#zhonger_ld_heg__xusheng"] = "江东的铁壁",
  ["designer:zhonger_ld_heg__xusheng"] = "淬毒",
  ["illustrator:zhonger_ld_heg__xusheng"] = "天信",
  ["ld__yicheng"] = "疑城",
  [":ld__yicheng"] = "当一名与你势力相同的角色使用【杀】指定第一个目标后,或成为【杀】的目标后，你可以令其摸一张牌，然后弃置一张牌。",
  ["#ld__yicheng-ask"] = "是否发动疑城",
  ["$ld__yicheng1"] = "不怕死，就尽管放马过来！",
  ["$ld__yicheng2"] = "待末将布下疑城，以退曹贼。",
  ["~zhonger_ld_heg__xusheng"] = "可怜一身胆略，尽随一抔黄土……",
}

local jiangqin = General(extension, "zhonger_ld_heg__jiangqin", "wu", 4)
local shangyi = fk.CreateActiveSkill{
  name = 'ze_ld__shangyi',
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#ze_ld__shangyi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id 
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    if player.dead or target.dead or player:isKongcheng() then return end
    U.viewCards(target, player:getCardIds("h"), self.name)
    local choices = {}
    if H.getGeneralsRevealedNum(target) ~= 2 then
      table.insert(choices, "ze_ld__shangyi_hidden")
    end
    if not target:isKongcheng() then
      table.insert(choices, "ze_ld__shangyi_card")
    end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name)
    if choice == "ze_ld__shangyi_hidden" then
      local general = {target:getMark("__heg_general"), target:getMark("__heg_deputy"), target.seat}
      room:askForCustomDialog(player, self.name, "packages/ol_hegemony/qml/KnownBothBox.qml", general)
    elseif choice == "ze_ld__shangyi_card" then
      if table.find(target:getCardIds("h"), function(id) return Fk:getCardById(id).color == Card.Black end) then
        local card, _ = U.askforChooseCardsAndChoice(player, table.filter(target:getCardIds("h"), function(id) return Fk:getCardById(id).color == Card.Black end), 
        {"OK"}, self.name, "", nil, 1, 1, target:getCardIds("h"))
        room:throwCard(card, self.name, target, player)
      else
        U.viewCards(player, target:getCardIds("h"), self.name)
      end
    end
  end,
}
local niaoxiang = H.CreateArraySummonSkill{
  name = "ze_ld_niaoxiang",
  array_type = "siege",
}
local niaoxiangTrigger = fk.CreateTriggerSkill{
  name = "#ze_ld_niaoxiang_trigger",
  visible = false,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.trueName == "slash" and H.inSiegeRelation(target, player, player.room:getPlayerById(data.to)) 
      and #player.room.alive_players > 3 and H.hasShownSkill(player,"ze_ld_niaoxiang")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("ze_ld_niaoxiang")
    data.fixedResponseTimes = data.fixedResponseTimes or {}
    data.fixedResponseTimes["jink"] = 2
  end
}
jiangqin:addSkill(shangyi)
niaoxiang:addRelatedSkill(niaoxiangTrigger)
jiangqin:addSkill(niaoxiang)
jiangqin:addCompanions("zhonger_st_heg__zhoutai")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__jiangqin"] = "蒋钦",
  ["#zhonger_ld_heg__jiangqin"] = "祁奚之器",
  ["designer:zhonger_ld_heg__jiangqin"] = "淬毒",
  ["illustrator:zhonger_ld_heg__jiangqin"] = "天空之城",
  ["cv:zhonger_ld_heg__jiangqin"] = "小六",
  ["ze_ld__shangyi"] = "尚义",
  [":ze_ld__shangyi"] = "出牌阶段限一次，你可令一名其他角色观看你所有手牌，然后你选择一项：1.观看其所有手牌并弃置其中一张黑色牌；2.观看其所有暗置的武将牌。",
  ["ze_ld__shangyi_hidden"] = "观看暗置的武将牌",
  ["ze_ld__shangyi_card"] = "观看所有手牌",
  ["#ze_ld__shangyi"] = "尚义:选择一名其他角色",

  ["ze_ld_niaoxiang"]="鸟翔",
  ["#ze_ld_niaoxiang_trigger"] = "鸟翔",
  [":ze_ld_niaoxiang"] = "阵法技，若你是围攻角色，此围攻关系中的围攻角色使用【杀】指定被围攻角色为目标后，你令被围攻角色响应此【杀】的方式改为依次使用两张【闪】。",
 
  ["$ze_ld__shangyi1"] = "大丈夫为人坦荡，看下手牌算什么。",
  ["$ze_ld__shangyi2"] = "敌情已了然于胸，即刻出发！",
  ["$ze_ld_niaoxiang1"] = '此战，必是有死无生！',
  ["$ze_ld_niaoxiang2"] = '抢占先机，占尽优势！',
  ["~zhonger_ld_heg__jiangqin"] = "竟破我阵法...",
}

local yuji = General(extension, "zhonger_ld_heg__yuji", "qun", 3)
yuji:addSkill("qianhuan")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__yuji"] = "于吉",
  ["#zhonger_ld_heg__yuji"] = "魂绕左右",
  ["designer:zhonger_ld_heg__yuji"] = "淬毒",
  ["illustrator:zhonger_ld_heg__yuji"] = "G.G.G.",
  ["~zhonger_ld_heg__yuji"] = "幻化之物，终是算不得真呐。",
}

local hetaihou = General(extension, "zhonger_ld_heg__hetaihou", "qun", 3, 3, General.Female)
hetaihou:addSkill("zhendu")
hetaihou:addSkill("qiluan")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__hetaihou"] = "何太后",
  ["#zhonger_ld_heg__hetaihou"] = "弄权之蛇蝎",
  ["cv:zhonger_ld_heg__hetaihou"] = "水原",
  ["illustrator:zhonger_ld_heg__hetaihou"] = "KayaK&木美人",
  ["designer:zhonger_ld_heg__hetaihou"] = "淬毒",
  ["~zhonger_ld_heg__hetaihou"] = "你们男人造的孽，非要说什么红颜祸水……",
}

local lidian = General(extension, "zhonger_ld_heg__lidian", "wei", 3)
lidian:addSkill("xunxun")
lidian:addSkill("wangxi")
lidian:addCompanions("zhonger_st_heg__yuejin")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__lidian"] = "李典",
  ["#zhonger_ld_heg__lidian"] = "深明大义",
  ["designer:zhonger_ld_heg__lidian"] = "KayaK",
  ["illustrator:zhonger_ld_heg__lidian"] = "张帅",
  ["~zhonger_ld_heg__lidian"] = "报国杀敌，虽死犹荣……",
}

local zangba = General(extension, "zhonger_ld_heg__zangba", "wei", 4)
local hengjiang = fk.CreateTriggerSkill{
  name = "ldhengjiang",
  anim_type = "masochism",
  events = { fk.Damaged },
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if self.cancel_cost or player.dead then break end
      self:doCost(event, target, player, data)
    end
  end,
  can_trigger = function(self, _, target, player, _)
    if target ~= player or not player:hasSkill(self) then return false end
    local current = player.room.current
    return current ~= nil and not current.dead
  end,
  on_use = function(_, _, _, player, data)
    local room = player.room
    local target = room.current
    local nums = math.max(#target:getCardIds(Player.Equip),1)
    if target ~= nil and not target.dead then
      room:doIndicate(player.id, {target.id})
      room:addPlayerMark(target, "@ldhengjiang-turn", nums)
      room:addPlayerMark(target, MarkEnum.MinusMaxCardsInTurn, nums)
    end
  end
}
local hengjiangdelay = fk.CreateTriggerSkill{
  name = "#ldhengjiang_delay",
  anim_type = "drawcard",
  events = { fk.TurnEnd },
  --FIXME:如何体现这个技能是延迟效果？
  can_trigger = function(_, _, target, player, _)
    if player.dead or player:usedSkillTimes(hengjiang.name) == 0 then return false end
    local room = player.room
    local discard_ids = {}
    room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
      if e.data[2] == Player.Discard then
        table.insert(discard_ids, {e.id, e.end_id})
      end
      return false
    end, Player.HistoryTurn)
    if #discard_ids > 0 then
      if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
        local in_discard = false
        for _, ids in ipairs(discard_ids) do
          if #ids == 2 and e.id > ids[1] and e.id < ids[2] then
            in_discard = true
            break
          end
        end
        if in_discard then
          for _, move in ipairs(e.data) do
            if move.from == target.id and move.moveReason == fk.ReasonDiscard then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                  return true
                end
              end
            end
          end
        end
        return false
      end, Player.HistoryTurn) > 0 then
        return false
      end
    end
    return true
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = math.min(player.maxHp, 5) - player:getHandcardNum()
    if num > 0 then
    player:drawCards(num, hengjiang.name)
    end
  end,
}
hengjiang:addRelatedSkill(hengjiangdelay)
zangba:addSkill(hengjiang)
zangba:addCompanions("zhonger_st_heg__zhangliao")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__zangba'] = '臧霸',
  ["#zhonger_ld_heg__zangba"] = "节度青徐",
  ["illustrator:zhonger_ld_heg__zangba"] = "HOOO",
  ["ldhengjiang"] = '横江',
  [":ldhengjiang"] = "当你受到1点伤害后，你可以令当前回合角色本回合手牌上限-X(X为其装备区里的牌数且至少为1)，"..
    "然后本回合结束时，若其未于本回合的弃牌阶段弃置过其手牌，你将手牌摸至体力上限。",
  ["@ldhengjiang-turn"] = '横江',
  ["#ldhengjiang_delay"] = '横江',
  ["$ldhengjiang1"] = '霸必奋勇杀敌，一雪夷陵之耻！',
  ["$ldhengjiang2"] = '江横索寒，阻敌绝境之中！',
  ['~zhonger_ld_heg__zangba'] = '断刃沉江，负主重托……',
}

local madai = General(extension, "zhonger_ld_heg__madai", "shu", 4)
madai:addSkill("heg_madai__mashu")
madai:addSkill("re__qianxi")
madai:addCompanions("zhonger_st_heg__machao")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__madai"] = "马岱",
  ["#zhonger_ld_heg__madai"] = "临危受命",
  ["designer:zhonger_ld_heg__madai"] = "官方",
  ["illustrator:zhonger_ld_heg__madai"] = "Thinking",
  ["heg_madai__mashu"] = "马术",
  [":heg_madai__mashu"] = "锁定技，你与其他角色的距离-1。",
  ["~zhonger_ld_heg__madai"] = "我怎么会死在这里……",
}

local mifuren = General(extension, "zhonger_ld_heg__mifuren", "shu", 3, 3, General.Female)
local ldguixiu = fk.CreateTriggerSkill{
  name = "ldguixiu",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.GeneralRevealed, "fk.GeneralRemoved"},
  can_trigger = function(self, event, target, player, data)
    if target ~= player then return false end
    if event == "fk.GeneralRemoved" then
      return player:isWounded() and table.contains(Fk.generals[data]:getSkillNameList(), self.name)
    else
      if player:hasSkill(self) then
        for _, v in pairs(data) do
          if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#ldguixiu-" .. (event == fk.GeneralRevealed and "draw" or "recover"))
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.GeneralRevealed then
      player:drawCards(2, self.name)
    else
      player.room:recover{
        who = player,
        num = 1,
        skillName = self.name,
      }
    end
  end
}
mifuren:addSkill(ldguixiu)
mifuren:addSkill("cunsi")
mifuren:addRelatedSkill("yongjue")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__mifuren'] = '糜夫人',
  ["#zhonger_ld_heg__mifuren"] = "乱世沉香",
  ["designer:zhonger_ld_heg__mifuren"] = "淬毒",
  ["illustrator:zhonger_ld_heg__mifuren"] = "木美人",

  ["ldguixiu"] = "闺秀",
  [":ldguixiu"] = "当你：1.明置此武将牌后，你可摸两张牌：2.移除此武将牌后，你回复1点体力。",
  ["#ldguixiu-draw"] = "是否发动“闺秀”，摸两张牌",
  ["#ldguixiu-recover"] = "是否发动“闺秀”，回复1点体力",  

  ["$ldguixiu1"] = "闺中女子，亦可秀气英拔。",
  ["$ldguixiu2"] = "闺楼独看花月，倚窗顾影自怜。",  
  ["~zhonger_ld_heg__mifuren"] = "阿斗被救，妾身再无牵挂…",
}

local sunce = General(extension, "zhonger_ld_heg__sunce", "wu", 4)
sunce.deputyMaxHpAdjustedValue = -1
sunce:addCompanions { "zhonger_st_heg__zhouyu", "zhonger_st_heg__taishici", "zhonger_st_heg__daqiao" }
sunce:addSkill("jiang")
sunce:addSkill("yingyang")
sunce:addSkill("hunshang")
sunce:addRelatedSkill("heg_sunce__yingzi")
sunce:addRelatedSkill("heg_sunce__yinghun")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__sunce'] = '孙策',
  ["#zhonger_ld_heg__sunce"] = "江东的小霸王",
  ["designer:zhonger_ld_heg__sunce"] = "KayaK（韩旭）",
  ["illustrator:zhonger_ld_heg__sunce"] = "木美人",
  ["~zhonger_ld_heg__sunce"] = "内事不决问张昭，外事不决问周瑜……",
}

local chengdong = General(extension, "zhonger_ld_heg__chenwudongxi", "wu", 4)
local duanxie = fk.CreateActiveSkill{
  name = "zhonger_ld_heg__duanxie",
  anim_type = 'offensive',
  prompt = "#duanxie-active",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function() return false end,
  target_filter = function(self, to_select, selected,player)
    if #selected == 0 and to_select ~= Self.id then
      return true
    else
    return #selected < Self:getLostHp() and to_select ~= Self.id and
      not Fk:currentRoom():getPlayerById(to_select).chained
    end
  end,
  min_target_num = 1,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.clone(effect.tos)
    table.insert(targets, 1, effect.from)
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      local p = room:getPlayerById(id)
      if not p.dead and not p.chained then
      p:setChainState(true)
  if not player.chained then
      player:setChainState(true)
       end
     end
    end
  end,
}
local fenming = fk.CreateActiveSkill{
  name = "zhonger_ld_heg__fenming",
  anim_type = 'control',
  prompt = "#fenming-active",
  card_num = 0,
  can_use = function(self, player)
    return  player:hasSkill(self)  and player.chained and 
    player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    for _, p in ipairs(room:getAlivePlayers()) do
      if p.chained and not p:isNude() then
        local c = room:askForCardChosen(player, p, "he", self.name)
        room:throwCard(c, self.name, p, player)
      end
    end
  end,
}
chengdong:addSkill(duanxie)
chengdong:addSkill(fenming)
Fk:loadTranslationTable{
  ['zhonger_ld_heg__chenwudongxi'] = '陈武董袭',
  ["#zhonger_ld_heg__chenwudongxi"] = "壮怀激烈",
  ["designer:zhonger_ld_heg__chenwudongxi"] = "淬毒",
  ["illustrator:zhonger_ld_heg__chenwudongxi"] = "地狱许",
  ["zhonger_ld_heg__duanxie"] = "断绁",
  ["#duanxie-active"] = "断绁：你可以令至多X名其他角色横置（X为你已损失的体力值且至少为1）",
  ["zhonger_ld_heg__fenming"] = "奋命",
  ["#fenming-active"] = "奋命：你可弃置所有处于横置状态角色的各一张牌",
  [":zhonger_ld_heg__duanxie"] = "出牌阶段限一次，你可以令至多X名其他角色横置（X为你已损失的体力值且至少为1），然后你横置。",
  [":zhonger_ld_heg__fenming"] = "出牌阶段限一次，若你处于横置状态，你可弃置所有处于横置状态角色的各一张牌。",
  ["$zhonger_ld_heg__duanxie1"] = "区区绳索就想挡住吾等去路？！",
  ["$zhonger_ld_heg__duanxie2"] = "以身索敌，何惧同伤！",
  ["$zhonger_ld_heg__fenming1"] = "东吴男儿，岂是贪生怕死之辈？",
  ["$zhonger_ld_heg__fenming2"] = "不惜性命，也要保主公周全！",
  ["~zhonger_ld_heg__chenwudongxi"] = "杀身卫主，死而无憾！",
}

local dongzhuo = General(extension, "zhonger_ld_heg__dongzhuo", "qun", 4)
dongzhuo:addSkill("hengzheng")
dongzhuo:addSkill("baoling")
dongzhuo:addRelatedSkill("benghuai")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__dongzhuo'] = '董卓',
  ["#zhonger_ld_heg__dongzhuo"] = "魔王",
  ["designer:zhonger_ld_heg__dongzhuo"] = "KayaK（韩旭）",
  ["illustrator:zhonger_ld_heg__dongzhuo"] = "巴萨小马",
  ['~zhonger_ld_heg__dongzhuo'] = '为何人人……皆与我为敌？',
}

local zhangren = General(extension, "zhonger_ld_heg__zhangren", "qun", 4)
zhangren:addSkill("chuanxin")
zhangren:addSkill("fengshi")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__zhangren'] = '张任',
  ["#zhonger_ld_heg__zhangren"] = "索命神射",
  ["designer:zhonger_ld_heg__zhangren"] = "淬毒",
  ["illustrator:zhonger_ld_heg__zhangren"] = "DH",
  ['~zhonger_ld_heg__zhangren'] = '本将军败于诸葛，无憾……',
}

local xunyou = General(extension, "zhonger_ld_heg__xunyou", "wei", 3)
local qice = fk.CreateActiveSkill{
  name = "ze_ld__qice",
  prompt = "#ze_ld__qice-active",
  interaction = function()
    local handcards = Self:getCardIds(Player.Hand)
    local names, all_names = {} , {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card:isCommonTrick() and not card.is_derived and not table.contains(all_names, card.name) then
        table.insert(all_names, card.name)
        local to_use = Fk:cloneCard(card.name)
        to_use:addSubcards(handcards)
        if Self:canUse(to_use) and not Self:prohibitUse(to_use) then
          local x = 0
          if to_use.multiple_targets and to_use.skill:getMinTargetNum() == 0 then
            for _, p in ipairs(Fk:currentRoom().alive_players) do
              if not Self:isProhibited(p, card) and card.skill:modTargetFilter(p.id, {}, Self.id, card, true) then
                x = x + 1
              end
            end
          end
          if x <= Self:getHandcardNum() then
            table.insert(names, card.name)
          end
        end
      end
    end
    if #names == 0 then return end
    return U.CardNameBox {choices = names, all_choices = all_names}
  end,
  card_num = 0,
  min_target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    if self.interaction.data == nil then return false end
    local to_use = Fk:cloneCard(self.interaction.data)
    to_use.skillName = self.name
    to_use:addSubcards(Self:getCardIds(Player.Hand))
    if not to_use.skill:targetFilter(to_select, selected, selected_cards, to_use) then return false end
    if (#selected == 0 or to_use.multiple_targets) and
    Self:isProhibited(Fk:currentRoom():getPlayerById(to_select), to_use) then return false end
    if to_use.multiple_targets then
      if #selected >= Self:getHandcardNum() then return false end
      if to_use.skill:getMaxTargetNum(Self, to_use) == 1 then
        local x = 0
        for _, p in ipairs(Fk:currentRoom().alive_players) do
          if p.id == to_select or (not Self:isProhibited(p, to_use) and to_use.skill:modTargetFilter(p.id, {to_select}, Self.id, to_use, true)) then
            x = x + 1
          end
        end
        if x > Self:getHandcardNum() then return false end
      end
    end
    return true
  end,
  feasible = function(self, selected, selected_cards)
    if self.interaction.data == nil then return false end
    local to_use = Fk:cloneCard(self.interaction.data)
    to_use.skillName = self.name
    to_use:addSubcards(Self:getCardIds(Player.Hand))
    return to_use.skill:feasible(selected, selected_cards, Self, to_use)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local use = {
      from = player.id,
      tos = table.map(effect.tos, function (id)
        return {id}
      end),
      card = Fk:cloneCard(self.interaction.data),
    }
    use.card:addSubcards(player:getCardIds(Player.Hand))
    use.card.skillName = self.name
    room:useCard(use)
    if not player.dead and player:getMark("@@zeld__qice_transform") == 0 and room:askForChoice(player, {"transform_deputy", "Cancel"}, self.name) ~= "Cancel" then
      room:setPlayerMark(player, "@@zeld__qice_transform", 1)
      H.transformGeneral(room, player,false,3,false)
    end
  end,
}

xunyou:addSkill(qice)
xunyou:addSkill("zhiyu")
xunyou:addCompanions("zhonger_st_heg__xunyu")

Fk:loadTranslationTable{
  ["zhonger_ld_heg__xunyou"] = "荀攸",
  ["#zhonger_ld_heg__xunyou"] = "曹魏的谋主",
  ["designer:zhonger_ld_heg__xunyou"] = "淬毒",
  ["illustrator:zhonger_ld_heg__xunyou"] = "心中一凛",

  ["ze_ld__qice"] = "奇策",
  [":ze_ld__qice"] = "出牌阶段限一次，你可将所有手牌当任意一张普通锦囊牌使用，你不能以此法使用目标数大于X的牌（X为你的手牌数），然后你可变更副将。",

  ["#ze_ld__qice-active"] = "发动 奇策，将所有手牌当一张锦囊牌使用",
  ["@@zeld__qice_transform"] = "奇策 已变更",

  ["$ze_ld__qice1"] = "倾力为国，算无遗策。",
  ["$ze_ld__qice2"] = "奇策在此，谁与争锋？",
  ["~zhonger_ld_heg__xunyou"] = "主公，臣下……先行告退……",
}


local bianfuren = General(extension, "zhonger_ld_heg__bianfuren", "wei", 3, 3, General.Female)
local wanwei = fk.CreateTriggerSkill{
  name = "hsld__wanwei",
  events = {fk.BeforeCardsMove},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    local _data = {}
    for index, move in ipairs(data) do
      local num = 0
      if (move.moveReason == fk.ReasonPrey or move.moveReason == fk.ReasonDiscard) and move.from == player.id and move.proposer ~= player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand then
            num = num + 1
          end
        end
      end
      if num ~= 0 then
        table.insert(_data, {index, num})
      end
    end
    if #_data == 0 then return end
    self.cost_data = _data
    return true
  end,
  on_use = function(self, event, target, player, data)
    if player.dead then return end
    local room = player.room
    local _data = self.cost_data
    for _, tab in ipairs(_data) do
      local index, num = tab[1], tab[2]
      local ids = room:askForCardsChosen(player, player, num, num, "he", self.name, "#hsld__wanwei-choose")
      if #ids == num then
        local moveInfo = {}
        for _, id in ipairs(ids) do
          local from = room:getCardArea(id)
          local info = {}
          info.cardId = id
          info.fromArea = from
          table.insertIfNeed(moveInfo, info)
        end
        if #moveInfo == num then
          data[index].moveInfo = moveInfo
        end
      end
    end
  end,
}
local yuejian = fk.CreateTriggerSkill{
  name = "zhonger_ld_heg__yuejian",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return H.compareKingdomWith(player, target) and player:hasSkill(self) and target.phase == Player.Discard 
      and target:getMark("zhonger_ld_heg__yuejian-turn") == 0 and player.room.current == target
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    room:addPlayerMark(target, "_yuejian_maxcard-turn", 1)
  end,

  refresh_events = {fk.TargetSpecified},
  can_refresh = function(self, event, target, player, data)
    return H.compareKingdomWith(target, player) and target == player.room.current
      and target:getMark("zhonger_ld_heg__yuejian-turn") == 0 and data.firstTarget and data.card.type ~= Card.TypeEquip
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(AimGroup:getAllTargets(data.tos)) do
      if not H.compareKingdomWith(room:getPlayerById(id), target) then
        room:addPlayerMark(target, "zhonger_ld_heg__yuejian-turn", 1)
        break
      end
    end
  end,
}
local yuejian_maxcards = fk.CreateMaxCardsSkill{
  name = "#ze_yuejian_maxcards",
  fixed_func = function(self, player)
    if player:getMark("_yuejian_maxcard-turn") > 0 then
      return player.maxHp
    end
  end
}
yuejian:addRelatedSkill(yuejian_maxcards)
bianfuren:addCompanions("zhonger_st_heg__caocao")
bianfuren:addSkill(wanwei)
bianfuren:addSkill(yuejian)

Fk:loadTranslationTable{
  ["zhonger_ld_heg__bianfuren"] = "卞夫人",
  ["#zhonger_ld_heg__bianfuren"] = "奕世之雍容",
  ["illustrator:zhonger_ld_heg__bianfuren"] = "雪君S",
  ["hsld__wanwei"] = "挽危",
  [":hsld__wanwei"] = "当你的牌被其他角色弃置或获得时，你可改为你选择的等量的牌。",
  ["#hsld__wanwei-choose"] = "挽危：请选择等量即将被其他角色弃置或获得的牌",
  ["zhonger_ld_heg__yuejian"] = "约俭",
  [":zhonger_ld_heg__yuejian"] = "锁定技，与你势力相同角色的弃牌阶段开始时，若其本回合未对其他势力角色使用过牌，则其本回合的手牌上限改为其体力上限。",
  ["$zhonger_ld_heg__yuejian1"] = "吾母仪天下，于节俭处当率先垂范。",
  ["$zhonger_ld_heg__yuejian2"] = "取上为贪，取下为伪，妾则取其中者。",
  ["$hsld__wanwei1"] = "梁、沛之间，非子廉无有今日。",
  ["$hsld__wanwei2"] = "正使祸至，共死何苦！",
  ["~zhonger_ld_heg__bianfuren"] = "心肝涂地，惊愕断绝。",
}

local shamoke = General(extension, "zhonger_ld_heg__shamoke", "shu", 4)
shamoke:addSkill("jilis")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__shamoke'] = '沙摩柯',
  ["#zhonger_ld_heg__shamoke"] = "五溪蛮王",
  ["illustrator:zhonger_ld_heg__shamoke"] = "LiuHeng",
  ["designer:zhonger_ld_heg__shamoke"] = "韩旭",
  ['~zhonger_ld_heg__shamoke'] = '五溪蛮夷，不可能输！',
}

local masu = General(extension, "zhonger_ld_heg__masu", "shu", 3)
local zhiman = fk.CreateTriggerSkill{
  name = "ze_ld__zhiman",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to ~= player
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#zeld__zhiman-invoke::"..data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target = data.to
    if #target:getCardIds{Player.Equip, Player.Judge} > 0 then -- 开摆！
      local card = room:askForCardChosen(player, target, "ej", self.name)
      room:obtainCard(player.id, card, true, fk.ReasonPrey)
    end
    if H.compareKingdomWith(target, player) and player:getMark("@@zeld__zhiman_transform") == 0
      and room:askForChoice(player, {"zeld__zhiman_transform::" .. target.id, "Cancel"}, self.name) ~= "Cancel"
      and room:askForChoice(target, {"transform_deputy", "Cancel"}, self.name) ~= "Cancel" then
        room:setPlayerMark(player, "@@zeld__zhiman_transform", 1)
        H.transformGeneral(room, target,false,3,false)
    end
    return true
  end
}
masu:addSkill("sanyao")
masu:addSkill(zhiman)
Fk:loadTranslationTable{
  ['zhonger_ld_heg__masu'] = '马谡',
  ["#zhonger_ld_heg__masu"] = "帷幄经谋",
  ["designer:zhonger_ld_heg__masu"] = "点点",
  ["illustrator:zhonger_ld_heg__masu"] = "蚂蚁君",
  ["ze_ld__zhiman"] = "制蛮",
  [":ze_ld__zhiman"] = "当你对其他角色造成伤害时，你可防止此伤害，你获得其装备区或判定区里的一张牌。若其与你势力相同，你可令其选择是否变更。",

  ["#zeld__zhiman-invoke"] = "制蛮：你可以防止对 %dest 造成的伤害，获得其场上的一张牌。若其与你势力相同，你可令其选择是否变更副将。",
  ["zeld__zhiman_transform"] = "令%dest选择是否变更副将",
  ["@@zeld__zhiman_transform"] = "制蛮 已变更",

  ["$ze_ld__zhiman1"] = "兵法谙熟于心，取胜千里之外！",
  ["$ze_ld__zhiman2"] = "丞相多虑，且看我的！",
  ["~zhonger_ld_heg__masu"] = "败军之罪，万死难赎……" ,
}

local lingtong = General(extension, "zhonger_ld_heg__lingtong", "wu", 4)
lingtong:addSkill("xuanlve")
lingtong:addSkill("yongjin")
lingtong:addCompanions("zhonger_st_heg__ganning")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__lingtong'] = '凌统',
  ["#zhonger_ld_heg__lingtong"] = "豪情烈胆",
  ["designer:zhonger_ld_heg__lingtong"] = "韩旭",
  ["illustrator:zhonger_ld_heg__lingtong"] = "F.源",
  ["~zhonger_ld_heg__lingtong"] = "大丈夫，不惧死亡……",
}

local lvfan = General(extension, "zhonger_ld_heg__lvfan", "wu", 3)

local diaodu = fk.CreateTriggerSkill{  --拿装备
  name = "ld__diaodu", 
  anim_type = "drawcard",
  events = {fk.EventPhaseStart,fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.EventPhaseStart then
    return target == player and target.phase == Player.Play and table.find(player.room.alive_players, function(p)
    return H.compareKingdomWith(p, player) and #p:getCardIds(Player.Equip) > 0 end) 
    end
    if event == fk.CardUsing then
      return H.compareKingdomWith(target, player) and (data.card.type == Card.TypeEquip or data.card.trueName == "heg_zhaoshu" ) and (player:hasShownSkill(self) or player == target) and target:getMark("ze_tiaodu-turn") == 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local targets = table.map(table.filter(room.alive_players, function(p)
        return H.compareKingdomWith(p, player) and #p:getCardIds(Player.Equip) > 0 end), Util.IdMapper)
      if #targets == 0 then return false end
      local target = room:askForChoosePlayers(player, targets, 1, 1, "#lddiaodu-choose", self.name, true)
      if #target > 0 then
        self.cost_data = target[1]
        return true
      end
    end
    if event == fk.CardUsing then
      return room:askForSkillInvoke(target, self.name, nil, "#lddiaodu-invoke")
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.CardUsing then --摸牌
      target:drawCards(1, self.name)
      target:addMark("ze_tiaodu-turn",1) --只能一次
    else
      local room = player.room
      local target = room:getPlayerById(self.cost_data)
      local cid = room:askForCardChosen(player, target, "e", self.name)
      room:obtainCard(player, cid, true, fk.ReasonPrey)
      if not table.contains(player:getCardIds(Player.Hand), cid) then return false end
      local card = Fk:getCardById(cid)
      if player.dead then return false end
      local targets = table.map(table.filter(room.alive_players, function(p) return   p ~= target end), Util.IdMapper)
      local to = room:askForChoosePlayers(player, targets, 1, 1, "#lddiaodu-give:::" .. card:toLogString(), self.name, true)
      if #to > 0 then
        room:moveCardTo(card, Card.PlayerHand, room:getPlayerById(to[1]), fk.ReasonGive, self.name, nil, true, player.id)
      end
    end
  end,
}
local diancai = fk.CreateTriggerSkill{
  name = "ld__diancai",
  events = {fk.EventPhaseEnd},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or target.phase ~= Player.Play or target == player then return false end
    local num = 0
    player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move and move.from and move.from == player.id and ((move.to and move.to ~= player.id) or not table.contains({Card.PlayerHand, Card.PlayerEquip}, move.toArea)) then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              num = num + 1
            end
          end
        end
      end
      return false
    end, Player.HistoryPhase)
    return num >= player.hp
  end,
  on_use = function(self, event, target, player, data)
    local num = player.maxHp - player:getHandcardNum()
    local room = player.room
    if num > 0 then
      player:drawCards(num, self.name)
    end
    if player:getMark("@@ld__diancai_transform") == 0 and room:askForChoice(player, {"transform_deputy", "Cancel"}, self.name) ~= "Cancel" then
      room:setPlayerMark(player, "@@ld__diancai_transform", 1)
      H.transformGeneral(room, player,false,3,false)
    end
  end,
}
lvfan:addSkill(diaodu)
lvfan:addSkill(diancai)
Fk:loadTranslationTable{
  ['zhonger_ld_heg__lvfan'] = '吕范',
  ["#zhonger_ld_heg__lvfan"] = "忠笃亮直",
  ["designer:zhonger_ld_heg__lvfan"] = "韩旭",
  ["illustrator:zhonger_ld_heg__lvfan"] = "铭zmy",

  ['ld__diaodu'] = '调度',
  [':ld__diaodu'] = '①当每回合首次有与你势力相同的角色使用装备牌时，其可摸一张牌。②出牌阶段开始时，你可获得一名与你势力相同的角色装备区里的一张牌，然后你可以将此牌交给另一名角色。',
  ["ld__diancai"] = "典财",
  [":ld__diancai"] = "其他角色的出牌阶段结束时，若你于此阶段失去过不少于X张牌（X为你的体力值），则你可将手牌摸至你体力上限，然后你可变更。",

  ["#lddiaodu-invoke"] = "调度：你可摸一张牌",
  ["#lddiaodu-choose"] = "调度：你可获得与你势力相同的一名角色装备区里的一张牌",
  ["#lddiaodu_draw"]="调度",
  ["#lddiaodu-give"] = "调度：将%arg交给另一名角色",
  ["#lddiancai-ask"] = "典财：你可摸 %arg 张牌，然后你可变更副将",

  ["@@ld__diancai_transform"] = "典财 已变更",

  ["$ld__diaodu1"] = "开源节流，作法于凉。",
  ["$ld__diaodu2"] = "调度征求，省行薄敛。",
  ["$ld__diancai1"] = "量入为出，利析秋毫。",
  ["$ld__diancai2"] = "天下熙攘，皆为利往。",
  ["~zhonger_ld_heg__lvfan"] = "闻主公欲授大司马之职，容臣不能……谢恩了……",
}

local zuoci = General(extension, "zhonger_ld_heg__zuoci", "qun", 3)
local wudile = fk.CreateTriggerSkill{
  name = "#wudile",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.id == data.to and player:getMark("#@@草泥马") ~= 0
  end,
  on_use = Util.TrueFunc,
  after_use = function (room,player)
    room:setPlayerMark(player, "#@@草泥马", 0)
  end
}
local huashen_blacklist = {}
local function Gethuashen(player, n)
  local room = player.room
  local generals = table.filter(room.general_pile, function (name)
    return not table.contains(huashen_blacklist, name)
  end)
  local mark = U.getPrivateMark(player, "&hunpo")
  for _ = 1, n do
    if #generals == 0 then break end
    local g = table.remove(generals, math.random(#generals))
    table.insert(mark, g)
    table.removeOne(room.general_pile, g)
  end
  U.setPrivateMark(player, "&hunpo", mark)
end
local gzjh = fk.CreateTriggerSkill{
  name = "gzjh",
  anim_type = "masochism",
  events = {fk.Damaged,fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damaged then 
    return player:hasSkill(self) and target == player and player:hasSkill("gzjh", true)
    end
    if event == fk.AfterDying then 
      return player:hasSkill(self) and target and not target.dead and
   not H.compareKingdomWith(target, player) and data.damage and data.damage.from and not data.damage.from.dead 
   and (target.general ~="anjiang" or target.deputyGeneral~="anjiang") and (player.general ~="anjiang" or player.deputyGeneral ~="anjiang")
    end
  end,
  on_use = function(self, event, target, player, data)
    Gethuashen(player, 1)
  end,
}
local gzyg = fk.CreateViewAsSkill{
  name = "gzyg",
  pattern = ".",
  interaction = function()
    local names = {}
    local mark = Self:getMark("@$gzyg-turn")
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if (card.type == Card.TypeBasic or (card.type == Card.TypeTrick and card.sub_type ~= Card.SubtypeDelayedTrick)) and not card.is_derived and (card.trueName ~= "jink") and (card.trueName ~= "nullification") then
        local to_use = Fk:cloneCard(card.name)
        if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
          if mark == 0 or (not table.contains(mark, card.trueName)) then
            table.insertIfNeed(names, card.name)
          end
        end
      end
    end
    if #names == 0 then return false end
    return U.CardNameBox { choices = names }
  end,
  view_as = function(self, cards)
    if #cards ~= 0 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local marke = player:getMark("@$gzyg-turn")
    if marke == 0 then marke = {} end
    table.insert(marke, use.card.trueName)
    local mark = U.getPrivateMark(player, "&hunpo")
    if #mark == 0 then return end
    local name = room:askForGeneral(player, mark, 1, true)
    local general = Fk.generals[name]
    local kingdom = tostring(general.kingdom)
    local mar = tostring(general.subkingdom)
      for _, p in ipairs(room:getAlivePlayers(player)) do
        if p.kingdom ~= kingdom  and p.kingdom ~= mar and (p.general~="anjiang" or p.deputyGeneral~="anjiang") then 
          room:setPlayerMark(p, "#@@草泥马", 1)
          room:handleAddLoseSkills(p, "#wudile")
        end
      end
    table.removeOne(mark, name)
    U.setPrivateMark(player, "&hunpo", mark)
    room:setPlayerMark(player, "@$gzyg-turn", marke)
    room:setPlayerMark(player, "@gzyg-used-turn", name)
  end,
  enabled_at_play = function(self, player)
    return #U.getPrivateMark(player, "&hunpo") > 0
  end,
  enabled_at_response = function(self, player, response)
    return #U.getPrivateMark(player, "&hunpo") > 0 and ((not response) or (not(table.every(Fk:currentRoom().alive_players, function(p) return not p.dying end))))
  end,
  after_use = function(self, player, use)
    local room = player.room
      for _, p in ipairs(room:getAlivePlayers(player)) do
        if p:hasSkill(wudile, true, true) then
          room:handleAddLoseSkills(p, '-#wudile')
          room:setPlayerMark(p, "#@@草泥马", 0)
        end
      end
      room:setPlayerMark(player, "#@@草泥马", 0)
      if player:hasSkill(wudile, true, true) then
        room:handleAddLoseSkills(player, '-#wudile') end
  end,
}
local xinsheng2 = fk.CreateTriggerSkill{
  name = "#fuckuu",
  events = {fk.GeneralRevealed},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) then return false end
    if event == fk.GeneralRevealed then
      if player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
        return not player:isFakeSkill(self)
      end
    else
      return false
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.GeneralRevealed then return true end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.GeneralRevealed then
      player:broadcastSkillInvoke("gzyg")
      Gethuashen(player, 2)
    end
  end,
}
local gundanba = fk.CreateTriggerSkill{
  name = "#gundanba",
  anim_type = "masochism",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.Death then
        return player:hasSkill(self, false, true)
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    if event == fk.Death then
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local to = 5
    if to > 0 then
      return true
    end
  end,
  after_use = function(self, player, use)
    local room = player.room
      for _, p in ipairs(player.room:getAlivePlayers(player)) do
        if p:hasSkill(wudile, true, true) then
          room:handleAddLoseSkills(p, '-#wudile')
          room:setPlayerMark(p, "#@@草泥马", 0)
        end
      end
      room:setPlayerMark(player, "#@@草泥马", 0)
      if player:hasSkill(wudile, true, true) then
        room:handleAddLoseSkills(player, '-#wudile') end
  end,
}
gzyg:addRelatedSkill(wudile)
gzyg:addRelatedSkill(xinsheng2)
gzyg:addRelatedSkill(gundanba)
zuoci:addSkill(gzyg)
zuoci:addSkill(gzjh)
zuoci:addCompanions("zhonger_ld_heg__yuji")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__zuoci"] = "左慈",
  ["#zhonger_ld_heg__zuoci"] = "鬼影神道",
  ["illustrator:zhonger_ld_heg__zuoci"] = "吕阳",
  ["@[private]&hunpo"] = "魂",
  ["gzjh_re"] = "进行一次“汲魂”",
  ["#gzyg_trigger"] = "役鬼",
  ["gzyg"] = "役鬼",
  ["#wudile"] = "役鬼",
  ["#gundanba"] = "役鬼",
  ["@gzyg-used-turn"]="魂→",
  ["$#wudile1"] = "容貌发肤，不过浮尘。",
  ["$#wudile2"] = "皮囊万千，吾皆可化。",
  [":gzyg"] = "当你首次明置此武将后，你将剩余武将牌堆中的两张武将牌扣置于武将牌上，称为“魂”。"..
    "每种牌名每回合限一次，你可以移去一张“魂”，视为使用一张基本牌或普通锦囊牌。此虚拟牌结算过程中，仅对与“魂”势力相同的角色及未确定势力的角色生效。",
  ["#js_lose_xinsheng"] = "请移除一张“魂”",
  ["gzjh"] = "汲魂",
  ["#xihun-ask"] = "是否发动汲魂,获得一张魂",
  ["#gzjh_xihun"] = "汲魂",
  ["@$gzyg-turn"] = "役鬼",
  [":gzjh"] = "①当你受到伤害后，你可以从剩余武将牌堆中扣置一张牌加入“魂”牌。"..
  "②当一名角色的濒死结算结束后，若其与你势力不同且存活，你可以从剩余武将牌堆中扣置一张牌加入“魂”牌。",
  ["#fuckuu"] = "役鬼",
  [":#fuckuu"] = "当你首次明置此武将后，你将剩余武将牌堆中的两张武将牌扣置于武将牌上，称为“魂”。"..
  "当一名角色的濒死结算结束后，若其与你势力不同且存活，你可以从剩余武将牌堆中扣置一张牌加入“魂”牌。",
  ["$gzyg1"] = "百鬼众魅，自缚见形。",
  ["$gzyg2"] = "来去无踪，众谓诡异。",
  ["$gzjh1"] = "魂聚则生，魂散则弃。",
  ["$gzjh2"] = "魂羽化游，以辅四方。",
  ["~zhonger_ld_heg__zuoci"] = "红尘看破，驾鹤仙升。",
}
local lijueguosi = General(extension, "zhonger_ld_heg__lijueguosi", "qun", 4)
lijueguosi:addCompanions("zhonger_st_heg__jiaxu")
lijueguosi:addSkill("xiongsuan")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__lijueguosi'] = '李傕郭汜',
  ["#zhonger_ld_heg__lijueguosi"] = "犯祚倾祸",
  ["designer:zhonger_ld_heg__lijueguosi"] = "千幻",
  ["illustrator:zhonger_ld_heg__lijueguosi"] = "旭",
  ["~zhonger_ld_heg__lijueguosi"] = "异心相争，兵败战损……",
}

local cuiyanmaojie = General(extension, "zhonger_ld_heg__cuiyanmaojie", "wei", 3)
local zhengbi = fk.CreateTriggerSkill{
  name = "ze_ld__zhengbi",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
      and (table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).type == Card.TypeBasic end) or table.every(player.room:getOtherPlayers(player), function(p) return H.getGeneralsRevealedNum(p) == 0 end))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    local basic_cards1 = table.filter(player:getCardIds(Player.Hand), function(id)
      return Fk:getCardById(id).type == Card.TypeBasic end)
    local targets1 = table.map(table.filter(room:getOtherPlayers(player), function(p)
      return H.getGeneralsRevealedNum(p) > 0 end), Util.IdMapper)
    local targets2 = table.map(table.filter(room:getOtherPlayers(player), function(p)
      return H.getGeneralsRevealedNum(p) == 0 end), Util.IdMapper)
    if #basic_cards1 > 0 and #targets1 > 0 then
      table.insert(choices, "ldzhengbi_giveCard")
    end
    if #targets2 > 0 then
      table.insert(choices, "ldzhengbi_useCard")
    end
    if #choices == 0 then return false end
    local choice = room:askForChoice(player, choices, self.name)
    if choice:startsWith("ldzhengbi_giveCard") then
      local tos, id = room:askForChooseCardAndPlayers(player, targets1, 1, 1, ".|.|.|.|.|basic", "#zeld__zhengbi-give", self.name, true)
      room:obtainCard(tos[1], id, false, fk.ReasonGive)
      local to = room:getPlayerById(tos[1])
      if to.dead or to:isNude() then return end
      local cards2 = to:getCardIds("he")
      if #cards2 > 1 then
        local card_choices = {}
        local num = #table.filter(to:getCardIds(Player.Hand), function(id)
          return Fk:getCardById(id).type == Card.TypeBasic end)
        if num > 1 then
          table.insert(card_choices, "ldzhengbi__basic-back:"..player.id)
        end
        if #to:getCardIds("he") - num > 0 then
          table.insert(card_choices, "ldzhengbi__nobasic-back:"..player.id)
        end
        if #card_choices == 0 then return false end
        local card_choice = room:askForChoice(to, card_choices, self.name)
        if card_choice:startsWith("ldzhengbi__basic-back") then
          cards2 = room:askForCard(to, 2, 2, false, self.name, false, ".|.|.|.|.|basic", "#zeld__zhengbi-give1:"..player.id)
        elseif card_choice:startsWith("ldzhengbi__nobasic-back") then
          cards2 = room:askForCard(to, 1, 1, true, self.name, false, ".|.|.|.|.|^basic", "#zeld__zhengbi-give2:"..player.id)
        end
      end
      room:moveCardTo(cards2, Player.Hand, player, fk.ReasonGive, self.name, nil, false, player.id)
    elseif choice:startsWith("ldzhengbi_useCard") then
      local to = room:askForChoosePlayers(player, targets2, 1, 1, "#zeld__zhengbi_choose", self.name, true)
      if #to then
        room:setPlayerMark(room:getPlayerById(to[1]), "@@zeld__zhengbi_choose-turn", 1)
      end
    end
  end,

  refresh_events = {fk.GeneralRevealed},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target:getMark("@@zeld__zhengbi_choose-turn") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(target, "@@zeld__zhengbi_choose-turn", 0)
  end,
}

local zhengbi_targetmod = fk.CreateTargetModSkill{
  name = "#ze_ld__zhengbi_targetmod",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:hasSkill(zhengbi) and to:getMark("@@zeld__zhengbi_choose-turn") > 0
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return card and player:hasSkill(zhengbi) and to:getMark("@@zeld__zhengbi_choose-turn") > 0
  end,
}
local fengying = fk.CreateActiveSkill{
  name = "ze_ld__fengying",
  anim_type = "support",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  can_use = function(self, player) 
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not player:isKongcheng() and not player:prohibitUse(Fk:cloneCard("threaten_emperor"))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:useVirtualCard("threaten_emperor", player:getCardIds(Player.Hand), player, player, self.name)
    local targets = table.map(table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) end), Util.IdMapper)
    if #targets > 0 then
      for _, pid in ipairs(targets) do
        local p = room:getPlayerById(pid)
        if not p.dead then
          p:drawCards(math.max(0, p.maxHp - p:getHandcardNum()), self.name)
        end
      end
    end 
  end,
}
zhengbi:addRelatedSkill(zhengbi_targetmod)
cuiyanmaojie:addSkill(zhengbi)
cuiyanmaojie:addSkill(fengying)
cuiyanmaojie:addCompanions("zhonger_st_heg__caopi")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__cuiyanmaojie"] = "崔琰毛玠",
  ["#zhonger_ld_heg__cuiyanmaojie"] = "日出月盛",
  ["designer:zhonger_ld_heg__cuiyanmaojie"] = "Virgopaladin（韩旭）",
  ["illustrator:zhonger_ld_heg__cuiyanmaojie"] = "兴游",

  ["ze_ld__zhengbi"] = "征辟",
  [":ze_ld__zhengbi"] = "出牌阶段开始时，你可选择一项：1.选择一名未确定势力的其他角色，直至其明置过武将牌或此回合结束，你对其使用牌无距离和次数限制；2.将一张基本牌交给一名有明置武将牌的其他角色，然后其交给你一张非基本牌或两张基本牌。",
  ["ze_ld__fengying"] = "奉迎",
  [":ze_ld__fengying"] = "限定技，出牌阶段，你可将所有手牌当【挟天子以令诸侯】（无视大势力限制）使用，然后所有与你势力相同的角色将手牌补至其体力上限。",
  
  ["ldzhengbi_giveCard"] = "交给有势力角色基本牌",
  ["ldzhengbi_useCard"] = "选择无势力角色用牌无限制",

  ["#zeld__zhengbi-give"] = "请选择一张基本牌，交给一名有势力的角色",
  ["ldzhengbi__basic-back"] = "交给%src两张基本牌",
  ["ldzhengbi__nobasic-back"] = "交给%src一张非基本牌",

  ["#zeld__zhengbi-give1"] = "征辟：请交给%src两张基本牌",
  ["#zeld__zhengbi-give2"] = "征辟：请交给%src一张非基本牌",

  ["#zeld__zhengbi_choose"] = "征辟：请选择一名未确定势力的角色，你对其使用牌无距离与次数限制",
  ["@@zeld__zhengbi_choose-turn"] = "征辟",

  ["$ze_ld__zhengbi1"] = "跅弛之士，在御之而已。",
  ["$ze_ld__zhengbi2"] = "内不避亲，外不避仇。",
  ["$ze_ld__fengying1"] = "二臣恭奉，以迎皇嗣。",
  ["$ze_ld__fengying2"] = "奉旨典选，以迎忠良。",
  ["~zhonger_ld_heg__cuiyanmaojie"] = "为世所痛惜，冤哉……",
}

local yujin = General(extension, "zhonger_ld_heg__yujin", "wei", 4)
yujin:addSkill("ld__jieyue")
yujin:addCompanions("zhonger_st_heg__xiahoudun")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__yujin'] = '于禁',
  ["#zhonger_ld_heg__yujin"] = "讨暴坚垒",
  ["designer:zhonger_ld_heg__yujin"] = "官方",
  ["illustrator:zhonger_ld_heg__yujin"] = "biou09",
  ["$ld__jieyue_zhonger_ld_heg__yujin1"] = "不动如泰山！",
  ["$ld__jieyue_zhonger_ld_heg__yujin2"] = "纪法严明，无懈可击。",
  ["~zhonger_ld_heg__yujin"] = "呃，晚节不保……",
}

local wangping = General(extension, "zhonger_ld_heg__wangping", "shu", 4)
wangping:addCompanions("zhonger_ld_heg__jiangwanfeiyi")
local jianglue = fk.CreateActiveSkill{
  name = "zhonger_ld_heg__jianglue",
  frequency = Skill.Limited,
  anim_type = "support",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local index = H.startCommand(player, self.name)
    local kingdom = H.getKingdom(player)
    for _, p in ipairs(room:getAlivePlayers()) do
      if p.kingdom == "unknown" and not p.dead then
        if H.getKingdomPlayersNum(room)[kingdom] >= #room.players // 2 and not table.find(room.alive_players, function(_p) return _p.general == "zhonger_lord_heg__liubei" end) then break end
        local main, deputy = false, false
        if H.compareExpectedKingdomWith(p, player) then
          local general = Fk.generals[p:getMark("__heg_general")]
          main = general.kingdom == kingdom or general.subkingdom == kingdom
          general = Fk.generals[p:getMark("__heg_deputy")]
          deputy = general.kingdom == kingdom or general.subkingdom == kingdom
        end
        H.askForRevealGenerals(room, p, self.name, main, deputy)
      end
    end
    local targets = table.map(table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) and p ~= player end), Util.IdMapper)
    local tos = {}
    if #targets > 0 then
      room:doIndicate(player.id, targets)
      room:sortPlayersByAction(targets)
      for _, pid in ipairs(targets) do
        local p = room:getPlayerById(pid)
        if player.dead then break end
        if not p.dead and H.doCommand(p, self.name, index, player) then
          table.insert(tos, pid)
        end
      end
    end
    table.insert(tos, 1, player.id)
    local num = 0
    for _, pid in ipairs(tos) do
      local p = room:getPlayerById(pid)
      if not p.dead then
        room:changeMaxHp(p, 1)
        if not p.dead then
          if room:recover({
            who = p,
            num = 1,
            recoverBy = player,
            skillName = self.name
          }) then
            num = num + 1
          end
        end
      end
    end
    if num > 0 then player:drawCards(num, self.name) end
  end
}
wangping:addSkill(jianglue)
Fk:loadTranslationTable{
  ["zhonger_ld_heg__wangping"] = "王平",
  ["#zhonger_ld_heg__wangping"] = "键闭剑门",
  ["illustrator:zhonger_ld_heg__wangping"] = "zoo",
  ["zhonger_ld_heg__jianglue"] = "将略",
  [":zhonger_ld_heg__jianglue"] = "限定技，出牌阶段，你可选择一个“军令”，然后你可以发动势力召唤，你对所有与你势力相同的角色发起此“军令”。你加1点体力上限，回复1点体力，所有执行“军令”的角色各加1点体力上限，回复1点体力。然后你摸X张牌（X为以此法回复体力的角色数）。",
  ["$zhonger_ld_heg__jianglue1"] = "奇谋为短，将略为要。",
  ["$zhonger_ld_heg__jianglue2"] = "为将者，需有谋略。",
  ["~zhonger_ld_heg__wangping"] = "无当飞军，也有困于深林之时……",
}

local fazheng = General(extension, "zhonger_ld_heg__fazheng", "shu", 3)
fazheng:addCompanions("zhonger_st_heg__liubei")
fazheng:addSkill("ld__enyuan")
local wushengXH = fk.CreateViewAsSkill{
  name = "xuanhur__hs__wusheng",
  anim_type = "offensive",
  pattern = "slash",
  expand_pile = "$carriage&",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    if(H.getHegLord(Fk:currentRoom(), Self) and H.getHegLord(Fk:currentRoom(), Self):hasSkill("shouyue")) and Fk:getCardById(to_select) then
      return true
    end
    if Fk:getCardById(to_select).color == Card.Red then return true end
    if (Self:getPileNameOfId(to_select) == "$carriage&") then
      return Fk:getCardById(to_select).color == Card.Red
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
local wusheng_targetmod = fk.CreateTargetModSkill{
  name = "#xuanhur__hs__wusheng_targetmod",
  anim_type = "offensive",
  bypass_distances = function (self, player, skill, card, to)
    return player:hasSkill(wushengXH) and skill.trueName == "slash_skill" and card.suit == Card.Diamond
  end
}
wushengXH:addRelatedSkill(wusheng_targetmod)
local paoxiaoTriggerXH = fk.CreateTriggerSkill{
  name = "#xuanhur__hs__paoxiaoTrigger",
  events = {fk.CardUsing},
  anim_type = "offensive",
  visible = false,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) or data.card.trueName ~= "slash" then return false end
    local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e) 
      local use = e.data[1]
      return use.from == player.id and use.card.trueName == "slash"
    end, Player.HistoryTurn)
    return #events == 2 and events[2].id == player.room.logic:getCurrentEvent().id
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,

  refresh_events = {fk.CardUsing, fk.TargetSpecified, fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    if player ~= target then return false end -- 摆一下
    if event == fk.CardUsing then
      return player:hasSkill(self) and data.card.trueName == "slash" and player:usedCardTimes("slash") > 1
    else
      local room = player.room
      if not H.getHegLord(room, player) or not H.getHegLord(room, player):hasSkill("shouyue") then return false end
      if event == fk.CardUseFinished then
        return (data.extra_data or {}).xhHsPaoxiaoNullifiled
      else
        return data.card.trueName == "slash" and player:hasSkill("xuanhur__hs__paoxiao") and room:getPlayerById(data.to):isAlive()
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      player:broadcastSkillInvoke("hs__paoxiao")
      room:doAnimate("InvokeSkill", {
        name = "paoxiao",
        player = player.id,
        skill_type = "offensive",
      })
    elseif event == fk.CardUseFinished then
      for key, num in pairs(data.extra_data.xhHsPaoxiaoNullifiled) do
        local p = room:getPlayerById(tonumber(key))
        if p:getMark(fk.MarkArmorNullified) > 0 then
          room:removePlayerMark(p, fk.MarkArmorNullified, num)
        end
      end
      data.xhHsPaoxiaoNullifiled = nil
    else
      room:addPlayerMark(room:getPlayerById(data.to), fk.MarkArmorNullified)
      data.extra_data = data.extra_data or {}
      data.extra_data.xhHsPaoxiaoNullifiled = data.extra_data.xhHsPaoxiaoNullifiled or {}
      data.extra_data.xhHsPaoxiaoNullifiled[tostring(data.to)] = (data.extra_data.xhHsPaoxiaoNullifiled[tostring(data.to)] or 0) + 1
    end
  end,
}
local paoxiaoXH = fk.CreateTargetModSkill{
  name = "xuanhur__hs__paoxiao",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope)
    if player:hasSkill(self) and skill.trueName == "slash_skill"
      and scope == Player.HistoryPhase then
      return true
    end
  end,
}
paoxiaoXH:addRelatedSkill(paoxiaoTriggerXH)
local longdanXH = fk.CreateViewAsSkill{
  name = "xuanhur__hs__longdan",
  pattern = "slash,jink",
  expand_pile = "$carriage&",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    local _c = Fk:getCardById(to_select) or Self:getPileNameOfId(to_select) == "$carriage&"
    local c
    if _c.trueName == "slash" then
      c = Fk:cloneCard("jink")
    elseif _c.name == "jink" then
      c = Fk:cloneCard("slash")
    else
      return false
    end
    return (Fk.currentResponsePattern == nil and Self:canUse(c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local _c = Fk:getCardById(cards[1])
    local c
    if _c.trueName == "slash" then
      c = Fk:cloneCard("jink")
    elseif _c.name == "jink" then
      c = Fk:cloneCard("slash")
    end
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
local longdanAfterXH = fk.CreateTriggerSkill{
  name = "#xuanhur__longdan_after",
  anim_type = "offensive",
  visible = false,
  events = {fk.CardEffectCancelledOut, fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      if data.card.trueName ~= "slash" then return false end
      if target == player then -- 龙胆杀
        return table.contains(data.card.skillNames, "xuanhur__hs__longdan")
      elseif data.to == player.id then -- 龙胆闪
        for _, card in ipairs(data.cardsResponded) do
          if card.name == "jink" and table.contains(card.skillNames, "xuanhur__hs__longdan") then
            return true
          end
        end
      end
    else
      local room = player.room
      return player == target and H.getHegLord(room, player) and table.contains(data.card.skillNames, "xuanhur__hs__longdan") and H.getHegLord(room, player):hasSkill("shouyue")
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardEffectCancelledOut then
      if target == player then
        local targets = table.map(room:getOtherPlayers(room:getPlayerById(data.to)), Util.IdMapper)
        if #targets == 0 then return false end
        local target = room:askForChoosePlayers(player, targets, 1, 1, "#longdan_slash-ask::" .. data.to, self.name, true)
        if #target > 0 then
          self.cost_data = target[1]
          return true
        end
        return false
      else
        local targets = table.map(table.filter(room:getOtherPlayers(target), function(p) return
          p ~= player and p:isWounded()
        end), Util.IdMapper)
        if #targets == 0 then return false end
        local target = room:askForChoosePlayers(player, targets, 1, 1, "#longdan_jink-ask::" .. target.id , self.name, true)
        if #target > 0 then
          self.cost_data = target[1]
          return true
        end
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    if event == fk.CardEffectCancelledOut then
      if target == player then
        room:damage{
          from = player,
          to = to,
          damage = 1,
          skillName = self.name,
        }
      else
        room:recover({
          who = to,
          num = 1,
          recoverBy = player,
          skillName = self.name,
        })
      end
    else
      player:drawCards(1, self.name)
    end
  end,
}
longdanXH:addRelatedSkill(longdanAfterXH)
local tieqiXH = fk.CreateTriggerSkill{
  name = "xuanhur__hs__tieqi",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|spade,club,heart,diamond",
    }
    if player.dead then return end
    local choices = {}
    if to.general ~= "anjiang" then
      table.insert(choices, to.general)
    end
    if to.deputyGeneral ~= "anjiang" then
      table.insert(choices, to.deputyGeneral)
    end
    if #choices > 0 then
      local choice
      if H.getHegLord(room, player) and #choices > 1 and H.getHegLord(room, player):hasSkill("shouyue") then
        choice = choices
      else
        choice = {room:askForChoice(player, choices, self.name, "#hs__tieqi-ask::" .. to.id)}
      end
      local record = to:getTableMark("@hs__tieqi-turn")
      for _, c in ipairs(choice) do
        table.insertIfNeed(record, c)
        room:setPlayerMark(to, "@hs__tieqi-turn", record)
        local mark = to:getTableMark("_hs__tieqi-turn")
        for _, skill_name in ipairs(Fk.generals[c]:getSkillNameList()) do
          if Fk.skills[skill_name].frequency ~= Skill.Compulsory then
            table.insertIfNeed(mark, skill_name)
          end
        end
        room:setPlayerMark(to, "_hs__tieqi-turn", mark)
      end
    end
    room:judge(judge)
    if judge.card.suit ~= nil then
      local suits = {}
      table.insert(suits, judge.card:getSuitString())
      if #room:askForDiscard(to, 1, 1, false, self.name, true, ".|.|" .. table.concat(suits, ","), "#hs__tieqi-discard:::" .. judge.card:getSuitString()) == 0 then
        data.disresponsive = true
      end
    end
  end,
}
local tieqiInvalidityXH = fk.CreateInvaliditySkill {
  name = "#xuanhur__hs__tieqi_invalidity",
  invalidity_func = function(self, from, skill)
    if from:getMark("_hs__tieqi-turn") ~= 0 then
      return table.contains(from:getMark("_hs__tieqi-turn"), skill.name) and
      (skill.frequency ~= Skill.Compulsory and skill.frequency ~= Skill.Wake) and not skill.name:endsWith("&")
    end
  end
}
tieqiXH:addRelatedSkill(tieqiInvalidityXH)
local liegongXH = fk.CreateTriggerSkill{
  name = "xuanhur__hs__firebow",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self)) then return end
    local room = player.room
    local to = room:getPlayerById(data.to)
    local filter = to.hp >= player.hp
    return data.card.trueName == "slash" and filter 
  end,
  on_use = function(self, event, target, player, data)
    local choices = {"xuanhur_firebow-damage","xuanhur_firebow-qiangzhong"}
    local room = player.room
    local choice = room:askForChoice(player, choices, self.name,"#xuanr_firebow-chosen")
    if choice == "xuanhur_firebow-damage" then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    else
    data.disresponsiveList = data.disresponsiveList or {}
    table.insert(data.disresponsiveList, data.to)
    end
  end,
}
local liegongXHAR = fk.CreateAttackRangeSkill{
  name = "#xuanhur__hs__firebowAR",
  correct_func = function(self, from, to)
    if from:hasSkill("xuanhur__hs__firebow") then
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if string.find(p.general, "lord") and p:hasSkill("shouyue") and p.kingdom == from.kingdom then
          return 1
        end
      end
    end
    return 0
  end,
}
local liegong_t = fk.CreateTargetModSkill{
  name = "#xuanhur__hs__firebow_targetmod",
    bypass_distances =  function(self, player, skill, card, target)
    if skill.trueName == "slash_skill" and player:hasSkill(liegongXH) then
      return card and target and target:getHandcardNum() <= player:getHandcardNum() 
    end
  end,
}
liegongXH:addRelatedSkill(liegongXHAR)
liegongXH:addRelatedSkill(liegong_t)
local kuangguXH = fk.CreateTriggerSkill{
  name = "xuanhur__hs__kuanggu",
  anim_type = "drawcard",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and (data.extra_data or {}).kuanggucheck
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      self:doCost(event, target, player, data)
      if self.cost_data == "Cancel" then break end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = {"draw1", "Cancel"}
    if player:isWounded() then
      table.insert(choices, 2, "recover")
    end
    self.cost_data = room:askForChoice(player, choices, self.name)
    return self.cost_data ~= "Cancel"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data == "recover" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    elseif self.cost_data == "draw1" then
      player:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.BeforeHpChanged},
  can_refresh = function(self, event, target, player, data)
    return data.damageEvent and player == data.damageEvent.from and player:distanceTo(target) < 2 and player:distanceTo(target) > -1
  end,
  on_refresh = function(self, event, target, player, data)
    data.damageEvent.extra_data = data.damageEvent.extra_data or {}
    data.damageEvent.extra_data.kuanggucheck = true
  end,
}
local xuanhuo = fk.CreateTriggerSkill{
  name = "ze__xuanhuo",
  mute = true,
  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed, fk.GeneralRevealed, fk.GeneralHidden},
  can_refresh = function(self, event, target, player, data)
    if player ~= target then return false end
    if event == fk.Deathed then return player:hasSkill(self, true, true)
    elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then return data == self
    else return true end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local players = room.alive_players
    local fazhengs = table.filter(players, function(p) return p:hasShownSkill(self) end)
    local xuanhuo_map = {}
    for _, p in ipairs(players) do
      local will_attach = false
      for _, fazheng in ipairs(fazhengs) do
        if (fazheng ~= p and H.compareKingdomWith(fazheng, p)) then
          will_attach = true
          break
        end
      end
      xuanhuo_map[p] = will_attach
    end
    for p, v in pairs(xuanhuo_map) do
      if v ~= p:hasSkill("ze__xuanhuo_other&") then
        room:handleAddLoseSkills(p, v and "ze__xuanhuo_other&" or "-ze__xuanhuo_other&", nil, false, true)
      end
    end
  end,
}
local xuanhuoOther = fk.CreateActiveSkill{
  name = "ze__xuanhuo_other&",
  prompt = "#xuanhuo-other",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and table.find(Fk:currentRoom().alive_players, function(p)
      return p:hasSkill(xuanhuo) and H.compareKingdomWith(p, player) and p ~= Self
    end)
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected < 1 and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.filter(room:getOtherPlayers(player), function(p) return p:hasShownSkill(xuanhuo) and H.compareKingdomWith(p, player) end)
    if #targets == 0 then return false end
    local to
    if #targets == 1 then
      to = targets[1]
    else
      to = room:getPlayerById(room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, nil, self.name, false)[1])
    end
    room:doIndicate(player.id, {to.id})
    to:broadcastSkillInvoke("ze__xuanhuo")
    room:moveCardTo(effect.cards, Player.Hand, to, fk.ReasonGive, self.name, nil, false, to.id)
    if player:isNude() or not room:askForDiscard(player, 1, 1, true, self.name, false, nil, "#ze__xuanhuo-ask") then return false end
    if player.dead then return false end
    local all_choices = {"xuanhur__hs__wusheng", "xuanhur__hs__paoxiao", "xuanhur__hs__longdan","xuanhur__hs__tieqi", "xuanhur__hs__firebow", "xuanhur__hs__kuanggu"}
    local choices = {}
    local skills = {}
    for _, p in ipairs(room.alive_players) do
      for _, s in ipairs(p.player_skills) do
        table.insert(skills, s.name)
      end
    end
    for _, skill in ipairs(all_choices) do
      local skillNames = {skill, skill:sub(10)}
      local can_choose = true
      for _, sname in ipairs(skills) do
        if table.contains(skillNames, sname) then
          can_choose = false
          break
        end
      end
      if can_choose then table.insert(choices, skill) end
    end
    if #choices == 0 then return false end

    local choice = room:askForChoice(player, choices, self.name, "#ze__xuanhuo-choice", true, all_choices)
    room:handleAddLoseSkills(player, choice, nil)
    room:addTableMark(player, "@ze__xuanhuo_skills-turn", choice)
  end,
}
local xuanhuoOtherLose = fk.CreateTriggerSkill{
  name = "#ze__xuanhuo_other_lose&",
  visible = false,
  refresh_events = {fk.EventPhaseStart, fk.GeneralRevealed},
  can_refresh = function(self, event, target, player, data)
    if type(player:getMark("@ze__xuanhuo_skills-turn")) ~= "table" then return false end
    if event == fk.EventPhaseStart then
      return target == player and player.phase == Player.NotActive
    else
      return true
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local _skills = player:getMark("@ze__xuanhuo_skills-turn")
      local skills = "-" .. table.concat(_skills, "|-")
      room:handleAddLoseSkills(player, skills, nil)
      room:setPlayerMark(player, "@ze__xuanhuo_skills-turn", 0)
    else
      local skills = {}
      table.forEach(room.alive_players, function(p) table.insertTable(skills, p.player_skills) end)
      local xuanhuoSkills = player:getMark("@ze__xuanhuo_skills-turn")
      if type(xuanhuoSkills) == "table" then
        local detachList = {}
        for _, skill in ipairs(skills) do
          local skillName = "xuanhur__" .. skill.name
          if (table.contains(xuanhuoSkills, skillName)) then
            table.removeOne(xuanhuoSkills, skillName)
            table.insert("-" .. skillName)
          end
        end
        if #detachList > 0 then
          room:handleAddLoseSkills(player, table.concat(detachList, "|"), nil)
          room:setPlayerMark(player, "@ze__xuanhuo_skills-turn", #xuanhuoSkills > 0 and xuanhuoSkills or 0)
        end
      end
    end
  end,
}
xuanhuoOther:addRelatedSkill(xuanhuoOtherLose)
Fk:addSkill(xuanhuoOther)
fazheng:addSkill(xuanhuo)
fazheng:addRelatedSkill(wushengXH)
fazheng:addRelatedSkill(paoxiaoXH)
fazheng:addRelatedSkill(longdanXH)
fazheng:addRelatedSkill(tieqiXH)
fazheng:addRelatedSkill(liegongXH)
fazheng:addRelatedSkill(kuangguXH)
Fk:loadTranslationTable{
  ["zhonger_ld_heg__fazheng"] = "法正",
  ["#zhonger_ld_heg__fazheng"] = "蜀汉的辅翼",
  ["illustrator:zhonger_ld_heg__fazheng"] = "黑白画谱",
  ["ze__xuanhuo"] = "眩惑",
  [":ze__xuanhuo"] = "与你势力相同的其他角色的出牌阶段限一次，其可交给你一张手牌，然后其弃置一张牌，选择下列技能中的一个：〖武圣〗〖咆哮〗〖龙胆〗〖铁骑〗〖烈弓〗〖狂骨〗（场上已有的技能无法选择）。其于此回合内或明置有其以此法选择的技能的武将牌之前拥有其以此法选择的技能。",
  ["ze__xuanhuo_other&"] = "眩惑",
  [":ze__xuanhuo_other&"] = "你可交给法正一张手牌，然后弃置一张牌，选择下列技能中的一个：〖武圣〗〖咆哮〗〖龙胆〗〖铁骑〗〖烈弓〗〖狂骨〗（场上已有的技能无法选择）。你于此回合内或明置有以此法选择的技能的武将牌之前拥有以此法选择的技能。",
  ["#xuanhuo-other"] = "眩惑：你可交给法正一张手牌，然后弃置一张牌",
  ["xuanhur__hs__wusheng"] = "武圣",
  ["xuanhur__hs__paoxiao"] = "咆哮",
  ["xuanhur__hs__longdan"] = "龙胆",
  ["xuanhur__hs__tieqi"] = "铁骑",
  ["xuanhur__hs__firebow"] = "烈弓",
  ["xuanhur_firebow-damage"] = "此【杀】的伤害+1",
  ["xuanhur_firebow-qiangzhong"] = "此【杀】不可被响应",
  ["#xuanr_firebow-chosen"] =  "烈弓：选择一项",
  ["xuanhur__hs__kuanggu"] = "狂骨",
  [":xuanhur__hs__wusheng"] = "你可将一张红色牌当【杀】使用或打出。你使用的方块【杀】无距离限制。",
  [":xuanhur__hs__paoxiao"] = "锁定技，你使用【杀】无次数限制。当你于一个回合内使用第二张【杀】时，你摸一张牌。",
  [":xuanhur__hs__longdan"] = "你可将【闪】当【杀】使用或打出，当此【杀】被一名角色使用的【闪】抵消后，你可对另一名角色造成1点伤害。你可将【杀】当【闪】使用或打出，当一名角色使用的【杀】被此【闪】抵消后，你可令另一名其他角色回复1点体力。",
  [":xuanhur__hs__tieqi"] = "当你使用【杀】指定目标后，你可判定，令其本回合一张明置的武将牌非锁定技失效，其需弃置一张与判定结果花色相同的牌，否则其不能使用【闪】抵消此【杀】。",
  [":xuanhur__hs__firebow"] = "你对手牌数小于等于你的角色使用【杀】无距离关系的限制。当你使用【杀】指定一个目标后，若其体力值大于等于你，你可以选择一项：1.令此【杀】对其造成的伤害+1；2.令其不能使用【闪】响应此【杀】。",
  [":xuanhur__hs__kuanggu"] = "当你对距离1以内的角色造成1点伤害后，你可摸一张牌或回复1点体力。",
  ["#xuanhur__hs__paoxiaoTrigger"] = "咆哮",
  ["#xuanhur__longdan_after"] = "龙胆",

  ["$xuanhur__hs__wusheng1"] = "刀锋所向，战无不克！",
  ["$xuanhur__hs__wusheng2"] = "逆贼，哪里走！",
  ["$xuanhur__hs__paoxiao1"] = "喝啊！",
  ["$xuanhur__hs__paoxiao2"] = "今，必斩汝马下！",
  ["$xuanhur__hs__longdan1"] = "能进能退，乃真正法器！",
  ["$xuanhur__hs__longdan2"] = "吾乃常山赵子龙也！",
  ["$xuanhur__hs__tieqi1"] = "目标敌阵，全军突击！",
  ["$xuanhur__hs__tieqi2"] = "敌人阵型已乱，随我杀！",
  ["$xuanhur__hs__firebow1"] = "龙骨成镞，矢破苍穹。",
  ["$xuanhur__hs__firebow2"] = "凤翎为羽，箭没坚城。",
  ["$xuanhur__hs__kuanggu1"] = "沙场驰骋，但求一败！",
  ["$xuanhur__hs__kuanggu2"] = "我自横扫天下，蔑视群雄又如何？",

  ["#ze__xuanhuo-ask"] = "眩惑：弃置一张牌",
  ["@ze__xuanhuo_skills-turn"] = "眩惑",
  ["#ze__xuanhuo-choice"]="眩惑：选择一个技能获得",
  ["$ze__xuanhuo1"] = "收人钱财，替人消灾。",
  ["$ze__xuanhuo2"] = "哼，叫你十倍奉还！",
  ["~zhonger_ld_heg__fazheng"] = "汉室复兴，我，是看不到了……",
}

local lukang = General(extension, "zhonger_ld_heg__lukang", "wu", 3, 3, General.Male)
local keshou_filter = fk.CreateActiveSkill{
  name = "#ze_ld__keshou_filter",
  min_card_num = 2,
  max_card_num = 2,
  prompt = "#keshou-heg",
  card_filter = function(self, to_select, selected)
    return table.every(selected, function(id)
      return Fk:getCardById(to_select).color == Fk:getCardById(id).color
    end)
  end,
  target_filter = Util.FalseFunc,
  can_use = Util.FalseFunc,
}
local keshou = fk.CreateTriggerSkill{
  name = "ze_ld__keshou",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and player == target and #target:getCardIds("he") > 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local result, dat = room:askForUseActiveSkill(player, "#ze_ld__keshou_filter", "#ze_ld__keshou:::" .. data.damage, true)
    if result then
      self.cost_data = dat.cards
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room 
    room:throwCard(self.cost_data, self.name, player, player)
    data.damage = data.damage - 1
    if player and H.getKingdomPlayersNum(room)[H.getKingdom(player)] == 1 then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|heart,diamond|.|.|.",
      }
      room:judge(judge)
      if judge.card.color == Card.Red then
        player:drawCards(1, self.name)
      end
    end
  end,
}
keshou:addRelatedSkill(keshou_filter)
--[[local zhuwei = fk.CreateTriggerSkill{
  name = "ze_ld__zhuwei",
  anim_type = "drawcard",
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) 
      and player.room:getCardArea(data.card) == Card.Processing and( data.card.trueName == "slash"  or (data.card:isCommonTrick() and data.card.is_damage_card
     )  )
        end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
    local current = room.current
    local choices = {"ze_ld__zhuwei_ask::" .. current.id, "Cancel"}
    if room:askForChoice(player, choices, self.name) ~= "Cancel" then
      room:addPlayerMark(current, "@ze_ld__zhuwei_buff-turn", 1)
      room:addPlayerMark(current, MarkEnum.AddMaxCardsInTurn, 1)
    end
  end,
}--]]
local zhuwei_yuan = fk.CreateTriggerSkill{--筑围刷新
  name = "ze_ld__zhuwei_yuan",
  mute = true,
  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed,fk.GeneralRevealed, fk.GeneralHidden},
  can_refresh = function(self, event, target, player, data)
    if player ~= target then return false end
    if event == fk.Deathed then return player:hasSkill(self, true, true)
    elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then return data == self
    else return true end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local players = room.alive_players
    local zhuweis = table.filter(players, function(p) return  p:hasShownSkill(self) end)
    local zhuwei_map = {}
    for _, p in ipairs(players) do
      local will_attach = false
      for _, zhuweiyuan in ipairs(zhuweis) do
        if ( H.compareKingdomWith(zhuweiyuan, p)) then
          will_attach = true
          break
        end
      end
      zhuwei_map[p] = will_attach
    end
  for p, v in pairs(zhuwei_map) do
    if v ~= p:hasSkill("ze_ld__zhuwei_other&") then
      room:handleAddLoseSkills(p, v and "ze_ld__zhuwei_other&" or "-ze_ld__zhuwei_other&", nil, false, true)
    end
  end
end,
}
local zhuwei = fk.CreateActiveSkill{
  name = "ze_ld__zhuwei_other&",
  anim_type = "support",
  prompt = "#ze_ld__zhuwei_ask",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:hasSkill(self)
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
    and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke("ze_ld__zhuwei_yuan")
    if #effect.cards > 0 then
      room:throwCard(effect.cards, self.name, player)
      room:addPlayerMark(player,"@ze_ld__zhuwei_buff-turn", 1)
      room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, 1)
    end
  end,
}
local zhuwei_targetmod = fk.CreateTargetModSkill{
  name = "#ze_ld__zhuwei_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@ze_ld__zhuwei_buff-turn") > 0 and scope == Player.HistoryPhase then
      return player:getMark("@ze_ld__zhuwei_buff-turn")
    end
  end,
}

lukang:addSkill(keshou)
zhuwei:addRelatedSkill(zhuwei_targetmod)
lukang:addSkill(zhuwei)
lukang:addCompanions("zhonger_st_heg__luxun")
Fk:loadTranslationTable{
  ["zhonger_ld_heg__lukang"] = "陆抗",
  ["#zhonger_ld_heg__lukang"] = "孤柱扶厦",
  ["illustrator:zhonger_ld_heg__lukang"] = "王立雄",

  ["ze_ld__keshou"] = "恪守",
  [":ze_ld__keshou"] = "当你受到伤害时，你可弃置两张颜色相同的牌，令此伤害值-1，然后若没有与你势力相同的其他角色，你判定，若结果为红色，你摸一张牌。",
  ["#ze_ld__keshou"] = "恪守：是否弃置两张颜色相同的牌，令你受到的%arg点伤害-1",
  ["ze_ld__zhuwei"] = "筑围",
  [":ze_ld__zhuwei"] = "当你的判定结果确定后，若此牌为【杀】或伤害类锦囊牌，你可以获得之，然后你可令当前回合角色手牌上限和使用【杀】的次数上限于此回合内+1。",
  ["ze_ld__zhuwei_yuan"] = "筑围",
  [":ze_ld__zhuwei_yuan"] = "与你势力相同的角色的出牌阶段限一次，其可以弃置一张装备牌，然后其的手牌上限和使用【杀】的次数上限于此回合内+1。",
  ["ze_ld__zhuwei_other&"] = "筑围",
  [":ze_ld__zhuwei_other&"] = "出牌阶段限一次，你可以弃置一张装备牌，然后你的手牌上限和使用【杀】的次数上限于此回合内+1。",
  ["#ze_ld__zhuwei_ask"] = "筑围：你可以弃置一张装备牌",
  ["@ze_ld__zhuwei_buff-turn"] = "筑围",

  ["#ze_ld__keshou_filter"] = "",
  ["#keshou-heg"] = "恪守：你可弃置两张颜色相同的牌，令此伤害值-1",
   
  ["$ze_ld__keshou1"] = "仁以待民，自处不败之势。",
  ["$ze_ld__keshou2"] = "宽济百姓，则得战前养备之机。",
  ["$ze_ld__zhuwei_yuan1"] = "背水一战，只为破敌。",
  ["$ze_ld__zhuwei_yuan2"] = "全线并进，连战克晋。",
  ["~zhonger_ld_heg__lukang"] = "吾既亡矣，又能存几时...",
}

local wuguotai = General(extension, "zhonger_ld_heg__wuguotai", "wu", 3, 3, General.Female)
wuguotai:addSkill("ld__buyi")
wuguotai:addSkill("ganlu")
wuguotai:addCompanions("zhonger_st_heg__sunjian")

Fk:loadTranslationTable{
  ['zhonger_ld_heg__wuguotai'] = '吴国太',
  ["#zhonger_ld_heg__wuguotai"] = "武烈皇后",
  ["illustrator:zhonger_ld_heg__wuguotai"] = "李秀森",
  ["$ganlu_zhonger_ld_heg__wuguotai1"] = "玄德实乃佳婿呀。",
  ["$ganlu_zhonger_ld_heg__wuguotai2"] = "好一个郎才女貌，真是天作之合啊。",
  ["~zhonger_ld_heg__wuguotai"] = "诸位卿家，还请尽力辅佐仲谋啊……",
}

local yuanshu = General(extension, "zhonger_ld_heg__yuanshu", "qun", 4)
yuanshu:addCompanions("zhonger_st_heg__jiling")
local yongsi = fk.CreateTriggerSkill{
  name = "zhonger_ld_heg__yongsi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.DrawNCards, fk.TargetConfirmed},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) then return false end
    if event == fk.TargetConfirmed then
      return data.card.trueName == "known_both" and not player:isKongcheng()
    else
      if not H.isBigKingdomPlayer(player) or table.find(player.room.alive_players, function(p)
        return table.find(p:getEquipments(Card.SubtypeTreasure), function(cid)
          return Fk:getCardById(cid).name == "jade_seal"
        end)
      end) then return false end
      return event == fk.DrawNCards or player.phase == Player.Play
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local card = Fk:cloneCard("known_both")
      local max_num = card.skill:getMaxTargetNum(player, card)
      local targets = {}
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not player:isProhibited(p, card) then
          table.insert(targets, p.id)
        end
      end
      if #targets == 0 or max_num == 0 then return end
      local to = room:askForChoosePlayers(player, targets, 1, max_num, "#zhonger_ld_heg__yongsi__jade_seal-ask", self.name, false)
      if #to > 0 then
        self.cost_data = to
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.EventPhaseStart then
      room:notifySkillInvoked(player, self.name, "control")
      local targets = table.map(self.cost_data, Util.Id2PlayerMapper)
      room:useVirtualCard("known_both", nil, player, targets, self.name)
    elseif event == fk.DrawNCards then
      room:notifySkillInvoked(player, self.name, "drawcard")
      data.n = data.n + 1
    else
      room:notifySkillInvoked(player, self.name, "negative")
      if not player:isKongcheng() then
        player:showCards(player:getCardIds(Player.Hand))
      end
    end
  end,
}
local yongsiBig = H.CreateBigKingdomSkill{
  name = "#zhonger_ld_heg__yongsi_big",
  fixed_func = function(self, player)
    return player:hasShownSkill(yongsi) and player.kingdom ~= "unknown" and not table.find(Fk:currentRoom().alive_players, function(p)
      return table.find(p:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "jade_seal"
      end)
    end)
  end
}
yongsi:addRelatedSkill(yongsiBig)
yuanshu:addSkill(yongsi)
yuanshu:addSkill("ld__weidi")

Fk:loadTranslationTable{
  ['zhonger_ld_heg__yuanshu'] = '袁术',
  ["#zhonger_ld_heg__yuanshu"] = "仲家帝",
  ["illustrator:zhonger_ld_heg__yuanshu"] = "YanBai",
  ['zhonger_ld_heg__yongsi'] = "庸肆",
  [':zhonger_ld_heg__yongsi'] = "锁定技，①若所有角色的装备区里均没有【玉玺】，你视为装备着【玉玺】；②当你成为【知己知彼】的目标后，展示所有手牌。",
  ["#zhonger_ld_heg__yongsi__jade_seal-ask"] = "庸肆：你视为使用一张【知己知彼】",
  ["$zhonger_ld_heg__yongsi1"] = "天下，即将尽归吾袁公路！",
  ["$zhonger_ld_heg__yongsi2"] = "朕今日雄踞淮南，明日便可一匡天下。",
  ["$ld__weidi_zhonger_ld_heg__yuanshu1"] = "传国玉玺在手，朕语便是天言！",
  ["$ld__weidi_zhonger_ld_heg__yuanshu2"] = "传朕旨意，诸部遵旨即可。",
  ["~zhonger_ld_heg__yuanshu"] = "仲朝国祚，本应千秋万代，薪传不息……",
}

local zhangxiu = General(extension, "zhonger_ld_heg__zhangxiu", "qun", 4)
zhangxiu:addSkill("ld__fudi")
zhangxiu:addSkill("ld__congjian")
zhangxiu:addCompanions("zhonger_st_heg__jiaxu")
Fk:loadTranslationTable{
  ['zhonger_ld_heg__zhangxiu'] = '张绣',
  ["#zhonger_ld_heg__zhangxiu"] = "北地枪王",
  ["designer:zhonger_ld_heg__zhangxiu"] = "官方",
  ["illustrator:zhonger_ld_heg__zhangxiu"] = "青岛磐蒲",
  ['~zhonger_ld_heg__zhangxiu'] = '若失文和，吾将何归？',
}

local lordliubei = General(extension, "zhonger_lord_heg__liubei", "shu", 4) --君刘备
lordliubei.hidden = true
H.lordGenerals["zhonger_st_heg__liubei"] = "zhonger_lord_heg__liubei"
local zhangwu = fk.CreateTriggerSkill{
  name = "zhangwu",
  anim_type = 'drawcard',
  events = {fk.BeforeCardsMove, fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.BeforeCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id and (move.to ~= player.id or (move.toArea ~= Card.PlayerEquip and move.toArea ~= Card.PlayerHand)) and
          (move.moveReason ~= fk.ReasonUse or player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data[1].card.name ~= "dragon_phoenix") then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand) and Fk:getCardById(info.cardId).name == "dragon_phoenix" then
              return true
            end
          end
        end
      end
    else
      for _, move in ipairs(data) do
        if move.to ~= player.id and (move.toArea == Card.PlayerEquip or move.toArea == Card.DiscardPile) then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).name == "dragon_phoenix" then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local ids = {}
    if event == fk.BeforeCardsMove then
      local mirror_moves = {}
      for _, move in ipairs(data) do
        if move.from == player.id and (move.to ~= player.id or (move.toArea ~= Card.PlayerEquip and move.toArea ~= Card.PlayerHand)) and
          (move.moveReason ~= fk.ReasonUse or player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data[1].card.name ~= "dragon_phoenix") then
          local move_info = {}
          local mirror_info = {}
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if (info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand) and Fk:getCardById(info.cardId).name == "dragon_phoenix" then
              table.insert(ids, id)
              table.insert(mirror_info, info)
            else
              table.insert(move_info, info)
            end
          end
          if #mirror_info > 0 then
            move.moveInfo = move_info
            local mirror_move = table.clone(move)
            mirror_move.to = nil
            mirror_move.toArea = Card.DrawPile
            mirror_move.drawPilePosition = -1
            mirror_move.moveInfo = mirror_info
            table.insert(mirror_moves, mirror_move)
          end
        end
      end
      player:showCards(ids)
      table.insertTable(data, mirror_moves)
      if not player.dead then
        player:drawCards(2, self.name) -- 大摆特摆
      end
    else
      for _, move in ipairs(data) do
        if move.to ~= player.id and (move.toArea == Card.PlayerEquip or move.toArea == Card.DiscardPile) then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).name == "dragon_phoenix" then
              table.insert(ids, info.cardId)
            end
          end
        end
      end
      player.room:obtainCard(player, ids, true, fk.ReasonPrey)
    end
  end,
}

local shouyue = fk.CreateTriggerSkill{
  name = "shouyue",
  anim_type = "support",
  events = {fk.GeneralRevealed},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self, true) then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    end
  end,
}

local jizhao = fk.CreateTriggerSkill{
  name = "jizhao",
  anim_type = "support",
  frequency = Skill.Limited,
  events = {fk.AskForPeaches},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.dying and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getHandcardNum() < player.maxHp then
      room:drawCards(player, player.maxHp - player:getHandcardNum(), self.name)
    end
    if player.hp < 2 and not player.dead then
      room:recover({
        who = player,
        num = 2 - player.hp,
        recoverBy = player,
        skillName = self.name,
      })
    end
    room:handleAddLoseSkills(player, "-shouyue|ex__rende", nil) -- 乐
  end,
}
lordliubei:addSkill(zhangwu)
lordliubei:addSkill(shouyue)
lordliubei:addSkill(jizhao)
lordliubei:addRelatedSkill("ex__rende")
Fk:loadTranslationTable{
  ["zhonger_lord_heg__liubei"] = "君刘备",
  ["#zhonger_lord_heg__liubei"] = "龙横蜀汉",
  ["designer:zhonger_lord_heg__liubei"] = "韩旭",
  ["illustrator:zhonger_lord_heg__liubei"] = "LiuHeng",
  ["zhangwu"] = "章武",
  [":zhangwu"] = "锁定技，①当【飞龙夺凤】移至弃牌堆或其他角色的装备区后，你获得此【飞龙夺凤】；②当你非因使用【飞龙夺凤】而失去【飞龙夺凤】前，你展示此【飞龙夺凤】，将此【飞龙夺凤】的此次移动的目标区域改为牌堆底，摸两张牌。",
  ["shouyue"] = "授钺",
  [":shouyue"] = "<b><font color='goldenrod'>君主技</font></b>，你拥有“五虎将大旗”。<br>" ..
  "#<b>五虎将大旗</b>：存活的蜀势力角色拥有的〖武圣〗、〖咆哮〗、〖龙胆〗、〖铁骑〗和〖烈弓〗分别按以下规则修改：<br>" ..
  "〖武圣〗：将“红色牌”改为“任意牌”；<br>"..
  "〖咆哮〗：增加描述“当你使用杀指定目标后，此【杀】无视其他角色的防具”；<br>"..
  "〖龙胆〗：增加描述“当你使用/打出因〖龙胆〗转化的普【杀】或【闪】时，你摸一张牌”；<br>"..
  "〖铁骑〗：将“一张明置的武将牌的非锁定技失效”改为“所有明置的武将牌的非锁定技失效”；<br>"..
  "〖烈弓〗：增加描述“你的攻击范围+1”。",
  ["jizhao"] = "激诏",
  [":jizhao"] = "限定技，当你处于濒死状态时，你可将手牌摸至X张（X为你的体力上限），将体力回复至2点，失去〖授钺〗并获得〖仁德〗。",

  ["$shouyue_zhonger_lord_heg__liubei1"] = "仁德为政，自得民心！",
  ["$shouyue_zhonger_lord_heg__liubei2"] = "民心所望，乃吾政所向！",
  ["$zhangwu_zhonger_lord_heg__liubei1"] = "众将皆言君恩，今当献身以报！",
  ["$zhangwu_zhonger_lord_heg__liubei2"] = "汉贼不两立，王业不偏安！",
  ["$jizhao_zhonger_lord_heg__liubei1"] = "匡扶汉室，岂能无诸将之助！",
  ["$jizhao_zhonger_lord_heg__liubei2"] = "大汉将士，何人敢战？",
  ["~zhonger_lord_heg__liubei"] = "汉室之兴，皆仰望丞相了……",
}

local lordzhangjiao = General(extension, "zhonger_lord_heg__zhangjiao", "qun", 4)--君张角
lordzhangjiao.hidden = true
H.lordGenerals["zhonger_st_heg__zhangjiao"] = "zhonger_lord_heg__zhangjiao"
local wuxin = fk.CreateTriggerSkill{
  name = "wuxin",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = H.getSameKingdomPlayersNum(room, nil, "qun")
    if player:hasSkill("hongfa") then
      num = num + #player:getPile("heavenly_army")
    end
    room:askForGuanxing(player, room:getNCards(num), nil, {0, 0}, self.name)
  end,
}

local hongfa = fk.CreateTriggerSkill{
  name = "hongfa",
  anim_type = "support",
  events = {fk.GeneralRevealed},
  frequency = Skill.Compulsory,
  derived_piles = "heavenly_army",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self, true) then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    end 
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(self.name, 1)
    player.room:notifySkillInvoked(player, self.name, "support")
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed, fk.GeneralRevealed, fk.GeneralHidden},
  can_refresh = function(self, event, target, player, data)
    if player ~= target then return false end
    if event == fk.Deathed then return player:hasSkill(self, true, true)
    elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then return data == self
    else return true end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local players = room.alive_players
    local godzhangjiaos = table.filter(players, function(p) return p:hasShownSkill(self) end)
    local hongfa_map = {}
    for _, p in ipairs(players) do
      local will_attach = false
      for _, godzhangjiao in ipairs(godzhangjiaos) do
        if H.compareKingdomWith(godzhangjiao, p) then
          will_attach = true
          break
        end
      end
      hongfa_map[p] = will_attach
    end
    for p, v in pairs(hongfa_map) do
      if v ~= p:hasSkill("heavenly_army_skill&") then
        room:handleAddLoseSkills(p, v and "heavenly_army_skill&" or "-heavenly_army_skill&", nil, false, true)
      end
    end
  end,
}

local heavenly_army_skill = fk.CreateViewAsSkill{
  name = "heavenly_army_skill&",
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#heavenly_army_skill-active",
  interaction = function()
    local cards = {}
    local kingdom = Self.kingdom
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if string.find(p.general, "lord") and p:hasSkill("hongfa") and p.kingdom == kingdom and #p:getPile("heavenly_army") > 0 then
        cards = table.map(p:getPile("heavenly_army"), function(id) return Fk:getCardById(id):toLogString() end)
        break
      end
    end
    if #cards == 0 then return end
    return UI.ComboBox {choices = cards} -- FIXME: expand_pile
  end,
  view_as = function(self, cards)
    if self.interaction.data == nil then return end
    local card = Fk:cloneCard("slash")
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = {}
    local kingdom = player.kingdom
    for _, p in ipairs(room.alive_players) do
      if string.find(p.general, "lord") and p:hasSkill("hongfa") and p.kingdom == kingdom and #p:getPile("heavenly_army") > 0 then
        cards = p:getPile("heavenly_army")
        break
      end
    end
    local card
    for _, id in ipairs(cards) do
      if Fk:getCardById(id):toLogString() == self.interaction.data then
        card = id
        break
      end
    end
    use.card:addSubcard(card)
    player:broadcastSkillInvoke("hongfa", math.random(4, 5))
    return
  end,
  enabled_at_play = function(self, player)
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if string.find(p.general, "lord") and p:hasSkill("hongfa") and p.kingdom == player.kingdom and #p:getPile("heavenly_army") > 0 then
        return true
      end
    end
  end,
  enabled_at_response = function(self, player)
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if string.find(p.general, "lord") and p:hasSkill("hongfa") and p.kingdom == player.kingdom and #p:getPile("heavenly_army") > 0 then
        return true
      end
    end
  end,
}
local heavenly_army_skill_trig = fk.CreateTriggerSkill{
  name = "#heavenly_army_skill_trig",
  mute = true,
  events = {fk.EventPhaseStart, fk.PreHpLost},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self) and player:hasSkill("hongfa")) then return end
    if event == fk.EventPhaseStart then
      return player.phase == Player.Start and #player:getPile("heavenly_army") == 0
    else
      return #player:getPile("heavenly_army") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return true
    else
      local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|heavenly_army", "#heavenly_army_skill-ask", "heavenly_army")
      if #card > 0 then
        self.cost_data = card[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke("hongfa", math.random(2, 3))
      room:notifySkillInvoked(player, "heavenly_army_skill&", "control")
      player:addToPile("heavenly_army", room:getNCards(H.getSameKingdomPlayersNum(room, nil, "qun") + #player:getPile("heavenly_army")), true, self.name)
    else
      player:broadcastSkillInvoke("hongfa", 6)
      room:notifySkillInvoked(player, "heavenly_army_skill&", "defensive")
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "heavenly_army", true, player.id)
      return true
    end
  end,
}
heavenly_army_skill:addRelatedSkill(heavenly_army_skill_trig)
Fk:addSkill(heavenly_army_skill)

local wendao = fk.CreateActiveSkill{
  name = "wendao",
  anim_type = "support",
  prompt = "#wendao",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      local card = Fk:getCardById(to_select)
      return card.color == Card.Red and card.name ~= "peace_spell" and not Self:prohibitDiscard(card)
    end
  end,
  target_filter = Util.FalseFunc,
  target_num = 0,
  card_num = 1,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    local card = room:getCardsFromPileByRule("peace_spell", 1, "discardPile")
    if #card > 0 then
      room:obtainCard(from, card[1], false, fk.ReasonPrey)
    else
      for _, p in ipairs(room.alive_players) do
        for _, id in ipairs(p:getCardIds(Player.Equip)) do
          if Fk:getCardById(id).name == "peace_spell" then
            room:obtainCard(from, id, false, fk.ReasonPrey)
            return false
          end
        end
      end
    end
  end,
}
lordzhangjiao:addSkill(wuxin)
lordzhangjiao:addSkill(hongfa)
lordzhangjiao:addSkill(wendao)
Fk:loadTranslationTable{
  ["zhonger_lord_heg__zhangjiao"] = "君张角",
  ["#lzhonger_lord_heg__zhangjiao"] = "时代的先驱",
  ["designer:zhonger_lord_heg__zhangjiao"] = "韩旭",
  ["illustrator:zhonger_lord_heg__zhangjiao"] = "青骑士",

  ["wuxin"] = "悟心",
  [":wuxin"] = "摸牌阶段开始时，你可观看牌堆顶的X张牌（X为群势力角色数）并可改变这些牌的顺序。",
  ["hongfa"] = "弘法",
  [":hongfa"] = "<b><font color='goldenrod'>君主技</font></b>，你拥有“黄巾天兵符”。<br>#<b>黄巾天兵符</b>：<br>" ..
          "①准备阶段，若没有“天兵”，你将牌堆顶的X张牌置于武将牌上（称为“天兵”）（X为群势力角色数）。<br>" ..
          "②每有一张“天兵”，你执行的效果中的“群势力角色数”便+1。<br>" ..
          "③当你的失去体力结算开始前，若有“天兵”，你可将一张“天兵”置入弃牌堆，终止此失去体力流程。<br>" ..
          "④与你势力相同的角色可将一张“天兵”当【杀】使用或打出。",
  ["wendao"] = "问道",
  [":wendao"] = "出牌阶段限一次，你可弃置一张不为【太平要术】的红色牌，然后你获得弃牌堆里或一名角色的装备区里的【太平要术】。",
  ["#wendao"] = "问道：你可弃置一张不为【太平要术】的红色牌，获得弃牌堆里或一名角色的装备区里的【太平要术】",
  ["heavenly_army"] = "天兵",

  ["heavenly_army_skill&"] = "天兵符",
  [":heavenly_army_skill&"] = "你可将一张“天兵”当【杀】使用或打出",
  ["#heavenly_army_skill-active"] = "黄巾天兵符：你可将一张“天兵”当【杀】使用或打出",
  ["#heavenly_army_skill_trig"] = "黄巾天兵符",
  ["#heavenly_army_skill-ask"] = "黄巾天兵符：你可移去一张“天兵”，防止此次失去体力",

  ["$wuxin_zhonger_lord_heg__zhangjiao1"] = "云涌风起，雷电聚集！",
  ["$wuxin_zhonger_lord_heg__zhangjiao2"] = "乾坤无极，风雷受命！",
  ["$hongfa1"] = "世间万法，殊途同归！", -- 亮将
  ["$hongfa2"] = "从无邪恶之法，唯有作恶之人！", -- 拿天兵
  ["$hongfa3"] = "从无邪恶之法，唯有作恶之人！", -- 拿天兵
  ["$hongfa4"] = "从无邪恶之法，唯有作恶之人！", -- 杀
  ["$hongfa5"] = "从无邪恶之法，唯有作恶之人！", -- 杀
  ["$hongfa6"] = "从无邪恶之法，唯有作恶之人！", -- 防止失去体力
  ["$wendao_zhonger_lord_heg__zhangjiao1"] = "汝等既顺黄天，当应天公之命！",
  ["$wendao_zhonger_lord_heg__zhangjiao2"] = "黄天佑我，道兵显威！",
  ["~zhonger_lord_heg__zhangjiao"] = "只叹未能覆汉，徒失天时。",
}

local lordsunquan = General(extension, "zhonger_lord_heg__sunquan", "wu", 4)--君孙权
lordsunquan.hidden = true
H.lordGenerals["zhonger_st_heg__sunquan"] = "zhonger_lord_heg__sunquan"
local jiahe = fk.CreateTriggerSkill{
  name = "jiahe",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.GeneralRevealed},
  derived_piles = "lord_fenghuo",
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self, true) then
      for _, v in pairs(data) do
        if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player, '#fenghuotu')
  end,
}

local fenghuotu = fk.CreateTriggerSkill{
  name = "#fenghuotu",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return H.compareKingdomWith(player, target) and player:hasSkill(self) and #player:getPile("lord_fenghuo") > 0 and target.phase == Player.Start
    else
      local type_remove = data.card and (data.card.type == Card.TypeTrick or data.card.trueName == "slash")
      if table.find(player.room.alive_players, function (p) return p:getMark("@@wk_heg__huanglong_change") ~= 0 end) then
        type_remove = data.card and (data.card.trueName == "slash")
      end
      return player == target and player:hasSkill(self) and #player:getPile("lord_fenghuo") > 0 and type_remove
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return true
    else
      local card = player.room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|lord_fenghuo", "#ld__jiahe_damaged", "lord_fenghuo")
      if #card > 0 then
        self.cost_data = card
        return true
    end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local skills = {"ld__lordsunquan_yingzi", "ld__lordsunquan_haoshi", "ld__lordsunquan_shelie", "ld__lordsunquan_duoshi"}
      local num = #player:getPile("lord_fenghuo") >= 5 and 2 or 1
      local result = room:askForCustomDialog(target, self.name,
      "packages/utility/qml/ChooseSkillBox.qml", {
        table.slice(skills, 1, #player:getPile("lord_fenghuo") + 1), 0, num, "#fenghuotu-choose:::" .. tostring(num)
      })
      if result == "" then return false end
      local choice = json.decode(result)
      if #choice > 0 then
        room:handleAddLoseSkills(target, table.concat(choice, "|"), nil, true, false)
        room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
          room:handleAddLoseSkills(target, '-' .. table.concat(choice, "|-"), nil, true, false)
        end)
      end
    else
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "lord_fenghuo", true, player.id)
    end
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed, fk.GeneralRevealed},
  can_refresh = function(self, event, target, player, data)
    if player ~= target then return false end
    if event == fk.Deathed then return player:hasSkill(self, true, true)
    elseif event == fk.EventAcquireSkill or event == fk.EventLoseSkill then return data == self
    else return true end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local players = room.alive_players
    local lordsunquans = table.filter(players, function(p) return p:hasShownSkill(self) end)
    local jiahe_map = {}
    for _, p in ipairs(players) do
      local will_attach = false
      for _, ld in ipairs(lordsunquans) do
        if H.compareKingdomWith(ld, p) then
          will_attach = true
          break
        end
      end
      jiahe_map[p] = will_attach
    end
    for p, v in pairs(jiahe_map) do
      if v ~= p:hasSkill("ld__jiahe_other&") then
        room:handleAddLoseSkills(p, v and "ld__jiahe_other&" or "-ld__jiahe_other&", nil, false, true)
      end
    end
  end,
}

local jiaheOther = fk.CreateActiveSkill{
  name = "ld__jiahe_other&",
  prompt = function()
    local to = H.getHegLord(Fk:currentRoom(), Self)
    return "#ld__jiahe_other:" .. to.id
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and H.getHegLord(Fk:currentRoom(), player) and H.getHegLord(Fk:currentRoom(), player):hasSkill("jiahe")
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected < 1 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = H.getHegLord(room, player)
    if to and to:hasSkill("jiahe") then
      to:addToPile("lord_fenghuo", effect.cards, true, self.name)
    end
  end,
}

local ld__yingzi = fk.CreateTriggerSkill{
  name = "ld__lordsunquan_yingzi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = data.n + 1
  end,

  refresh_events = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    return player == target and player:hasSkill(self) and player.phase == Player.Discard and not player:isFakeSkill(self.name)
  end,
  on_refresh = function(self, event, target, player, data)
    player:broadcastSkillInvoke(self.name)
    player.room:notifySkillInvoked(player, self.name, "defensive")
  end,
}
local ld__yingzi_maxcards = fk.CreateMaxCardsSkill{
  name = "#ld__lordsunquan_yingzi_maxcards",
  fixed_func = function(self, player)
    if player:hasSkill("ld__lordsunquan_yingzi") then
      return player.maxHp
    end
  end
}

local ld__haoshi = fk.CreateTriggerSkill{
  name = "ld__lordsunquan_haoshi",
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = data.n + 2
  end,
}
local ld__haoshi_delay = fk.CreateTriggerSkill{
  name = "#ld__lordsunquan_haoshi_delay",
  events = {fk.AfterDrawNCards},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:usedSkillTimes(ld__haoshi.name, Player.HistoryPhase) > 0 and
    #player.player_cards[Player.Hand] > 5 and #player.room.alive_players > 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player:getHandcardNum() // 2
    local targets = {}
    local n = 0
    for _, p in ipairs(room.alive_players) do
      if p ~= player then
        if #targets == 0 then
          table.insert(targets, p.id)
          n = p:getHandcardNum()
        else
          if p:getHandcardNum() < n then
            targets = {p.id}
            n = p:getHandcardNum()
          elseif p:getHandcardNum() == n then
            table.insert(targets, p.id)
          end
        end
      end
    end
    local tos, cards = room:askForChooseCardsAndPlayers(player, x, x, targets, 1, 1,
    ".|.|.|hand", "#haoshi-give:::" .. x, "ld__lordsunquan_haoshi", false)
    room:moveCardTo(cards, Card.PlayerHand, room:getPlayerById(tos[1]), fk.ReasonGive, "haoshi", nil, false, player.id)
  end,
}
local ld__shelie = fk.CreateTriggerSkill{
  name = "ld__lordsunquan_shelie",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(5)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonPut,
      skillName = self.name,
      proposer = player.id,
    })
    local get = {}
    for _, id in ipairs(cards) do
      local suit = Fk:getCardById(id).suit
      if table.every(get, function (id2)
        return Fk:getCardById(id2).suit ~= suit
      end) then
        table.insert(get, id)
      end
    end
    get = room:askForArrangeCards(player, self.name, cards, "#ld__lordsunquan_shelie-choose",
      false, 0, {5, 4}, {0, #get}, ".", "shelie", {{}, get})[2]
    if #get > 0 then
      room:obtainCard(player, get, true, fk.ReasonPrey)
    end
    cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonJustMove, self.name)
    end
    return true
  end,
}

local ld__duoshi = fk.CreateTriggerSkill{
  name = "ld__lordsunquan_duoshi",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    local card = Fk:cloneCard("await_exhausted")
    return player:hasSkill(self) and player == target and player.phase == Player.Play and not player:prohibitUse(card)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return
      H.compareKingdomWith(p, player) end)
    room:useVirtualCard("await_exhausted", {}, player, targets, self.name)
  end,
}

local lianzi = fk.CreateActiveSkill{
  name = "lianzi",
  anim_type = "drawcard",
  card_num = 1,
  target_num = 0,
  prompt = function()
    local show_num = #Self:getPile("lord_fenghuo")
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if H.compareKingdomWith(p, Self) then
        show_num = show_num + #p.player_cards[Player.Equip]
      end
    end
    return "#lianzi:::" .. show_num
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and not Self:prohibitDiscard(to_select) and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cardType = Fk:getCardById(effect.cards[1]).type
    room:throwCard(effect.cards, self.name, player)
    if player.dead then return end
    local show_num = #player:getPile("lord_fenghuo")
    for _, p in ipairs(room.alive_players) do
      if H.compareKingdomWith(p, player) then
        show_num = show_num + #p.player_cards[Player.Equip]
    end
    end
    if show_num == 0 then return end
    local cards = room:getNCards(show_num)
    room:moveCards{
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
      proposer = player.id
    }
    local to_get = table.filter(cards, function (id)
      return Fk:getCardById(id, true).type == cardType
    end)
    if #to_get > 0 then
      room:obtainCard(player.id, to_get, true, fk.ReasonJustMove)
      if #to_get > 3 then
        room:handleAddLoseSkills(player, "ld__lordsunquan_zhiheng|-lianzi", nil)
      end
    end
    cards = table.filter(cards, function (id)
      return room:getCardArea(id) == Card.Processing
    end)
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
    end
  end,
}

local ld__zhiheng = fk.CreateActiveSkill{
  name = "ld__lordsunquan_zhiheng",
  anim_type = "drawcard",
  prompt = "#ld__lordsunquan_zhiheng",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_num = 0,
  min_card_num = 1,
  max_card_num = function()
    return table.find(Self:getEquipments(Card.SubtypeTreasure), function(cid)
      return Fk:getCardById(cid).name == "luminous_pearl"
    end) and 998 or Self.maxHp
  end,
  card_filter = function(self, to_select, selected)
    if #selected >= Self.maxHp then
      return table.find(Self:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "luminous_pearl" and not table.contains(selected, cid) and to_select ~= cid
      end)
    end
    return #selected < Self.maxHp and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    if not from.dead then
      from:drawCards(#effect.cards, self.name)
    end
  end
}
local jubao = fk.CreateTriggerSkill{
  name = "ldjubao",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self) and player.phase == Player.Finish) then return false end
    for _, id in ipairs(player.room.discard_pile) do
      if Fk:getCardById(id).name == "ze_luminous_pearl" then
        return true
      end
    end
    return table.find(Fk:currentRoom().alive_players, function(p)
      return table.find(p:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "ze_luminous_pearl"
      end)
    end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    local targets = table.map(table.filter(room.alive_players, function(p)
      return table.find(p:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "ze_luminous_pearl"
      end) end), Util.IdMapper)
    if #targets > 0 then
      for _, pid in ipairs(targets) do
        local p = room:getPlayerById(pid)
        if p == player then
          local card = room:askForCardChosen(player, p, "e", self.name)
          room:obtainCard(player.id, card, false, fk.ReasonPrey)
        else
          local card = room:askForCardChosen(player, p, "he", self.name)
          room:obtainCard(player.id, card, false, fk.ReasonPrey)
        end
      end
    end
  end,
}
local jubao_move = fk.CreateTriggerSkill{
  name = "#ldjubao_move",
  events = {fk.BeforeCardsMove},
  frequency = Skill.Compulsory,
  anim_type = "defensive",
  -- main_skill = "jubao",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or not (player:getEquipment(Card.SubtypeTreasure)) then return false end
    for _, move in ipairs(data) do
      if move.from == player.id and move.to ~= move.from and move.toArea == Card.PlayerHand then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip and Fk:getCardById(info.cardId).sub_type == Card.SubtypeTreasure then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local ids = {}
    player.room:notifySkillInvoked(player, "ldjubao", "defensive")
    player:broadcastSkillInvoke("ldjubao")
    for _, move in ipairs(data) do
      if move.from == player.id and move.to ~= move.from and move.toArea == Card.PlayerHand then
        local move_info = {}
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          if info.fromArea == Card.PlayerEquip and Fk:getCardById(id).sub_type == Card.SubtypeTreasure then
            table.insert(ids, id)
          else
            table.insert(move_info, info)
          end
        end
        if #ids > 0 then
          move.moveInfo = move_info
        end
      end
    end
    if #ids > 0 then
      player.room:sendLog{
        type = "#cancelDismantle",
        card = ids,
        arg = self.name,
      }
    end
  end,
}
lordsunquan:addSkill(lianzi)
Fk:addSkill(ld__zhiheng)
ld__yingzi:addRelatedSkill(ld__yingzi_maxcards)
ld__haoshi:addRelatedSkill(ld__haoshi_delay)

lordsunquan:addSkill(jiahe)
Fk:addSkill(fenghuotu)
lordsunquan:addRelatedSkill(ld__yingzi)
lordsunquan:addRelatedSkill(ld__haoshi)
lordsunquan:addRelatedSkill(ld__shelie)
lordsunquan:addRelatedSkill(ld__duoshi)
Fk:addSkill(jiaheOther)

jubao:addRelatedSkill(jubao_move)
lordsunquan:addSkill(jubao)--聚宝
Fk:loadTranslationTable{
  ["zhonger_lord_heg__sunquan"] = "君孙权",
  ["#zhonger_lord_heg__sunquan"] = "虎踞江东",
  ["designer:zhonger_lord_heg__sunquan"] = "韩旭",
  ["illustrator:zhonger_lord_heg__sunquan"] = "瞌瞌一休",

  ["ldjubao"] = "聚宝",
  [":ldjubao"] = "锁定技，①结束阶段，若弃牌堆或场上存在【定澜夜明珠】，你摸一张牌，然后获得拥有【定澜夜明珠】的角色的一张牌；②其他角色获得你装备区内的宝物牌时，取消之。",
  ["#ldjubao_move"] = "聚宝",
  ["jiahe"] = "嘉禾",
  [":jiahe"] = "<b><font color='goldenrod'>君主技</font></b>，你拥有“缘江烽火图”。<br>" ..
  "#<b>缘江烽火图</b>：①吴势力角色出牌阶段限一次，其可将一张装备牌置于“缘江烽火图”上，称为“烽火”。<br>" ..
  "②吴势力角色的准备阶段，其可根据“烽火”数量选择获得对应的技能直至其回合结束：<br>"..
  "不小于一，〖英姿〗；不小于二，〖好施〗；不小于三，〖涉猎〗；不小于四，〖度势〗；不小于五，可额外选择一项。<br>"..
  "③锁定技，当你受到【杀】或锦囊牌造成的伤害后，你将一张“烽火”置入弃牌堆。",
  ["lianzi"] = "敛资",
  [":lianzi"] = "出牌阶段限一次，你可以弃置一张手牌并展示牌堆顶X张牌（X为吴势力角色装备区内牌数与“烽火”数之和），你获得其中与你弃置的牌类型相同的牌，将其余牌置入弃牌堆，然后若你因此获得至少四张牌，你失去〖敛资〗，获得〖制衡〗。",
  ["#ld__jiahe_damaged"] = "缘江烽火图：将一张“烽火”置入弃牌堆",
  ["ld__jiahe_other&"] = "烽火图",
  [":ld__jiahe_other&"] = "①出牌阶段限一次，你可以将一张装备牌置于“缘江烽火图”上，称为“烽火”。<br>" ..
  "②准备阶段，你可以根据“烽火”数量选择获得对应的技能直至其回合结束：<br>"..
  "不小于一，〖英姿〗；不小于二，〖好施〗；不小于三，〖涉猎〗；不小于四，〖度势〗；不小于五，可额外选择一项。",
  ["#fenghuotu"] = "缘江烽火图",
  ["#ld__jiahe_other"] = "缘江烽火图：将一张装备牌置于%src的“缘江烽火图”上，称为“烽火”",
  ["lord_fenghuo"] = "烽火",
  ["#ld__lordsunquan_haoshi_delay"] = "好施",
  ["#ld__lordsunquan_shelie-choose"] = "涉猎：获得不同花色的牌各一张",
  ["#fenghuotu-choose"] = "缘江烽火图：可选择%arg个技能",
  ["ld__lordsunquan_yingzi"] = "英姿",
  ["ld__lordsunquan_haoshi"] = "好施",
  ["ld__lordsunquan_shelie"] = "涉猎",
  ["ld__lordsunquan_duoshi"] = "度势",

  ["#lianzi"] = "敛资：你可以弃置一张手牌，然后亮出牌堆顶%arg张牌，获得其中与你弃置的牌类型相同的牌",

  [":ld__lordsunquan_yingzi"] = "锁定技，摸牌阶段，你多摸一张牌。你的手牌上限为你的体力上限。 ",
  [":ld__lordsunquan_haoshi"] = "摸牌阶段，你可以多摸两张牌，若如此做，此阶段结束时，若你的手牌数大于5，你将一半的手牌（向下取整）交给一名手牌数最小的其他角色。",
  [":ld__lordsunquan_shelie"] = "摸牌阶段，你可以改为亮出牌堆顶的五张牌，获得其中每种花色的牌各一张。 ",
  [":ld__lordsunquan_duoshi"] = "出牌阶段开始时，你可以视为使用一张【以逸待劳】。 ",

  ["ld__lordsunquan_zhiheng"] = "制衡",
  [":ld__lordsunquan_zhiheng"] = "出牌阶段限一次，你可以弃置至多X张牌（X为你体力上限），摸等量的牌。",
  ["#ld__lordsunquan_zhiheng"] = "制衡：你可以弃置至多%arg张牌",

  ["$fenghuotu1"] = "保卫国家，人人有责。",
  ["$fenghuotu2"] = "连绵的烽火，就是对敌人最好的震慑！",


  ["$jiahe_zhonger_lord_heg__sunquan1"] = "稳坐山河，但观世变。",
  ["$jiahe_zhonger_lord_heg__sunquan2"] = "身处惊涛，尤可弄潮。",
  ["$ldjubao1"] = "上下一心，君臣同志。",
  ["$ldjubao2"] = "胸有天下者，必可得其国。",
  ["$lianzi_zhonger_lord_heg__sunquan1"] = "汝救护有功，吾必当厚赐。",
  ["$lianzi_zhonger_lord_heg__sunquan2"] = "诸位将军，快快拦住贼军！",
  ["$ld__lordsunquan_zhiheng"] = "制衡联合，稳而不乱。",
  ["$ld__lordsunquan_yingzi"] = "贤臣良将在，我心安矣。",
  ["$ld__lordsunquan_haoshi"] = "多谢爱卿了。",
  ["$ld__lordsunquan_shelie"] = "有汝在此，自是放心。",
  ["$ld__lordsunquan_duoshi"] = "东吴俊杰良将在此，岂会败下阵来？",
  ["$fenghuotu_zhonger_lord_heg__sunquan"] = "三思而行，游刃有余。",
  ["~zhonger_lord_heg__sunquan"] = "风急举发，命不久矣……",
}

local lordcaocao = General(extension, "zhonger_lord_heg__caocao", "wei", 4)--君曹操
lordcaocao.hidden = true
H.lordGenerals["zhonger_st_heg__caocao"] = "zhonger_lord_heg__caocao"
local jieyueJA = fk.CreateTriggerSkill{
  name = "jianan__ld__jieyue",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and not player:isKongcheng() and table.find(player.room.alive_players, function(p) return
      p.kingdom ~= "wei"
    end)
  end,
  on_cost = function(self, event, target, player, data)
    local plist, cid = player.room:askForChooseCardAndPlayers(player, table.map(table.filter(player.room.alive_players, function(p) return
      p.kingdom ~= "wei" and p ~= player
    end), Util.IdMapper), 1, 1, ".|.|.|hand", "#jianan__ld__jieyue-target", self.name, true)
    if #plist > 0 then
      self.cost_data = {plist[1], cid}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = self.cost_data[1]
    local target = room:getPlayerById(to)
    room:moveCardTo(self.cost_data[2], Player.Hand, target, fk.ReasonGive, self.name, nil, false, player.id)
    if H.askCommandTo(player, target, self.name) then
      player:drawCards(1, self.name)
    else
      room:addPlayerMark(player, "_jianan__ld__jieyue-turn")
    end
  end
}
local jieyue_drawJA = fk.CreateTriggerSkill{
  name = "#jianan__ld__jieyue_draw",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  can_use = function(self, event, target, player, data)
    return target == player and target:getMark("_jianan__ld__jieyue-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 3 * target:getMark("_jianan__ld__jieyue-turn")
  end,
}

local tuxiJA = fk.CreateTriggerSkill{
  name = "jianan__ex__tuxi",
  anim_type = "control",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.n > 0 and
      not table.every(player.room:getOtherPlayers(player), function(p) return p:isKongcheng() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
      return not p:isKongcheng() end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, data.n, "#jianan__ex__tuxi-choose:::"..data.n, self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(self.cost_data) do
      local c = room:askForCardChosen(player, room:getPlayerById(id), "h", self.name)
      room:obtainCard(player, c, false, fk.ReasonPrey)
    end
    data.n = data.n - #self.cost_data
  end,
}

local qiaobianJA = fk.CreateTriggerSkill{
  name = "jianan__qiaobian",
  anim_type = "offensive",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isKongcheng() and
    data.to > Player.Start and data.to < Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local phase_name_table = {
      [3] = "phase_judge",
      [4] = "phase_draw",
      [5] = "phase_play",
      [6] = "phase_discard",
    }
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".", "#jianan__qiaobian-invoke:::" .. phase_name_table[data.to], true)
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    player:skip(data.to)
    if data.to == Player.Draw then
      local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return not p:isKongcheng() end), Util.IdMapper)
      if #targets > 0 then
        local n = math.min(2, #targets)
        local tos = room:askForChoosePlayers(player, targets, 1, n, "#jianan__qiaobian-choose:::"..n, self.name, true)
        if #tos > 0 then
          room:sortPlayersByAction(tos)
          for _, id in ipairs(tos) do
            local p = room:getPlayerById(id)
            if not p:isKongcheng() then
              local card_id = room:askForCardChosen(player, p, "h", self.name)
              room:obtainCard(player, card_id, false, fk.ReasonPrey)
            end
          end
        end
      end
    elseif data.to == Player.Play then
      local targets = room:askForChooseToMoveCardInBoard(player, "#jianan__qiaobian-move", self.name, true, nil)
      if #targets ~= 0 then
        targets = table.map(targets, function(id) return room:getPlayerById(id) end)
        room:askForMoveCardInBoard(player, targets[1], targets[2], self.name)
      end
    end
    return true
  end,
}

local xiaoguoJA = fk.CreateTriggerSkill{
  name = "jianan__hs__xiaoguo",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and target.phase == Player.Finish and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|.|.|.|basic", "#jianan__hs__xiaoguo-invoke::"..target.id, true)
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    if #room:askForDiscard(target, 1, 1, true, self.name, true, ".|.|.|.|.|equip", "#jianan__hs__xiaoguo-discard:"..player.id) == 0 then
      room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      }
    else
      player:drawCards(1, self.name)
    end
  end,
}

local duanliangJA = fk.CreateViewAsSkill{
  name = "jianan__hs__duanliang",
  anim_type = "control",
  pattern = "supply_shortage",
  expand_pile = "$carriage&",
  card_filter = function(self, to_select, selected)
    if Self:getPileNameOfId(to_select)  == "$carriage&" or Fk:getCardById(to_select) then
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black and Fk:getCardById(to_select).type ~= Card.TypeTrick
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("supply_shortage")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    local targets = TargetGroup:getRealTargets(use.tos)
    if #targets == 0 then return end
    local room = player.room
    for _, p in ipairs(targets) do
      if player:distanceTo(room:getPlayerById(p)) > 2 then
        room:setPlayerMark(player, "@@jianan__hs__duanliang-phase", 1)
      end
    end
  end
}
local duanliang_targetmodJA = fk.CreateTargetModSkill{
  name = "#jianan__hs__duanliang_targetmod",
  distance_limit_func =  function(self, player, skill)
    if player:hasSkill(duanliangJA) and skill.name == "supply_shortage_skill" then
      return 99
    end
  end,
}
local duanliang_invalidityJA = fk.CreateInvaliditySkill {
  name = "#jianan__hs__duanlianginvalidity",
  invalidity_func = function(self, from, skill)
    return from:getMark("@@jianan__hs__duanliang-phase") > 0 and
      skill.name == "jianan__hs__duanliang"
  end
}

local jianan = fk.CreateTriggerSkill{
  name = "jianan",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    if not (target == player and not target:isNude() and target.phase == Player.Start) then return end
    local lord = H.getHegLord(player.room, player)
    if lord and lord:hasSkill(self) then return true end
  end,
  on_cost = function (self, event, target, player, data)
    if #player.room:askForDiscard(target, 1, 1, true, self.name, true, nil, "#jianan-ask") > 0 then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local isDeputy = false
    if H.getGeneralsRevealedNum(target) == 1 then
      if target.general ~= "anjiang" then
        isDeputy = true
      elseif target.deputyGeneral ~= "anjiang" then
        isDeputy = false
      end
    elseif H.getGeneralsRevealedNum(target) == 2 then 
      isDeputy = H.doHideGeneral(room, target, target, self.name)
    end
    local record = target:getTableMark(MarkEnum.RevealProhibited)
    table.insert(record, isDeputy and "d" or "m")
    room:setPlayerMark(target, MarkEnum.RevealProhibited, record)

    local all_choices = {"jianan__ld__jieyue", "jianan__ex__tuxi", "jianan__qiaobian", "jianan__hs__duanliang", "jianan__hs__xiaoguo"}
    local choices = {}
    local skills = {}
    for _, p in ipairs(room.alive_players) do
      for _, s in ipairs(p.player_skills) do
        table.insert(skills, s.name)
      end
    end
    for _, skill in ipairs(all_choices) do
      local skillNames = {skill, skill:sub(9)}
      local can_choose = true
      for _, sname in ipairs(skills) do
        if table.contains(skillNames, sname) then
          can_choose = false
          break
        end
      end
      if can_choose then table.insert(choices, skill) end
    end
    if #choices == 0 then return false end
    local result = room:askForCustomDialog(target, self.name,
    "packages/utility/qml/ChooseSkillBox.qml", {
      choices, 1, 1, "#jianan-choice"
    })
    if result == "" then return false end
    local choice = json.decode(result)[1]
    room:handleAddLoseSkills(target, choice, nil)
    record = target:getTableMark("@jianan_skills")
    table.insert(record, choice)
    room:setPlayerMark(target, "@jianan_skills", record)
  end,
}

local jiananOtherLose = fk.CreateTriggerSkill{
  name = "#jianan_other_lose&",
  visible = false,
  refresh_events = {fk.TurnStart, fk.Death},
  can_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return target == player and player:hasSkill(jianan)
    end
    if event == fk.Death then
      return player:hasSkill(jianan, false, true) and player == target
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      local _skills = p:getMark("@jianan_skills")
      if _skills ~= 0 then
        local skills = "-" .. table.concat(_skills, "|-")
        room:handleAddLoseSkills(p, skills, nil)
        room:setPlayerMark(p, "@jianan_skills", 0)
      end
      room:setPlayerMark(p, MarkEnum.RevealProhibited, 0)
    end
  end,
}

local huibian = fk.CreateActiveSkill{
  name = "huibian",
  anim_type = "control",
  target_num = 2,
  card_num = 0,
  prompt = "#huibian-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    if #selected == 0 then
      local target2 = Fk:currentRoom():getPlayerById(to_select)
      return target2.kingdom == "wei"
    elseif #selected == 1 then
      local target1 = Fk:currentRoom():getPlayerById(to_select)
      return target1.kingdom == "wei" and target1:isWounded()
    else
      return false
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target1 = room:getPlayerById(effect.tos[1])
    local target2 = room:getPlayerById(effect.tos[2])
    room:damage{
      from = player,
      to = target1,
      damage = 1,
      skillName = self.name,
    }
    if not target1.dead then
      target1:drawCards(2, self.name)
    end
    if not target2.dead and target2:isWounded() then
      room:recover{
        who = target2,
        num = 1,
        recoverBy = player,
        skillName = self.name
      }
    end
  end,
}

local zongyu = fk.CreateTriggerSkill{
  name = "zongyu",
  anim_type = 'defensive',
  events = {fk.CardUsing, fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.to ~= player.id and move.toArea == Card.PlayerEquip then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).name == "liulongcanjia" then
              return true
            end
          end
        end
      end
    else
      if (data.card.sub_type == Card.SubtypeOffensiveRide or data.card.sub_type == Card.SubtypeDefensiveRide) and data.card.name ~= "liulongcanjia" and target == player then
        if #player.room:getCardsFromPileByRule("liulongcanjia", 1, "discardPile") > 0 then return true end
        return table.find(Fk:currentRoom().alive_players, function(p)
          return p ~= player and table.find(p:getEquipments(Card.SubtypeDefensiveRide), function(cid) return Fk:getCardById(cid).name == "liulongcanjia" end)
        end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.CardUsing then
      return true
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#zongyu-ask")
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.to ~= player.id and move.toArea == Card.PlayerEquip then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).name == "liulongcanjia" then
              local cards1 = {player:getEquipment(Fk:getCardById(info.cardId).sub_type)}
              local cards2 = {info.cardId}
              local move1 = {
                from = player.id,
                ids = cards1,
                toArea = Card.Processing,
                moveReason = fk.ReasonJustMove,
                proposer = player.id,
                skillName = self.name,
              }
              local move2 = {
                from = move.to,
                ids = cards2,
                toArea = Card.Processing,
                moveReason = fk.ReasonJustMove,
                proposer = player.id,
                skillName = self.name,
              }
              room:moveCards(move1, move2)
              local move3 = {
                ids = table.filter(cards1, function(id) return room:getCardArea(id) == Card.Processing end),
                fromArea = Card.Processing,
                to = move.to,
                toArea = Card.PlayerEquip,
                moveReason = fk.ReasonJustMove,
                proposer = player.id,
                skillName = self.name,
              }
              local move4 = {
                ids = table.filter(cards2, function(id) return room:getCardArea(id) == Card.Processing end),
                fromArea = Card.Processing,
                to = player.id,
                toArea = Card.PlayerEquip,
                moveReason = fk.ReasonJustMove,
                proposer = player.id,
                skillName = self.name,
              }
              room:moveCards(move3, move4)
              break
            end
          end
        end
      end
    else
      local to_throw = {data.card.id}
      if player:getEquipment(Card.SubtypeDefensiveRide) then
        table.insert(to_throw, player:getEquipment(Card.SubtypeDefensiveRide))
      end
      if player:getEquipment(Card.SubtypeOffensiveRide) then
        table.insert(to_throw, player:getEquipment(Card.SubtypeOffensiveRide))
      end
      room:moveCardTo(to_throw, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
      local card = room:getCardsFromPileByRule("liulongcanjia", 1, "discardPile")
      if #card == 0 then
        for _, p in ipairs(room:getOtherPlayers(player, false)) do
          for _, cid in ipairs(p:getEquipments(Card.SubtypeDefensiveRide)) do
            if Fk:getCardById(cid).name == "liulongcanjia" then
              card = {cid}
              break
            end
          end
          if #card > 0 then break end
        end
      end
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerEquip, player, fk.ReasonJustMove, self.name)
      end
    end
  end,
}

jieyueJA:addRelatedSkill(jieyue_drawJA)
duanliangJA:addRelatedSkill(duanliang_targetmodJA)
duanliangJA:addRelatedSkill(duanliang_invalidityJA)
jianan:addRelatedSkill(jiananOtherLose)

lordcaocao:addSkill(huibian)
lordcaocao:addSkill(jianan)
lordcaocao:addSkill(zongyu)

lordcaocao:addRelatedSkill(jieyueJA)
lordcaocao:addRelatedSkill(tuxiJA)
lordcaocao:addRelatedSkill(qiaobianJA)
lordcaocao:addRelatedSkill(xiaoguoJA)
lordcaocao:addRelatedSkill(duanliangJA)

Fk:loadTranslationTable{
  ["zhonger_lord_heg__caocao"] = "君曹操",
  ["#zhonger_lord_heg__caocao"] = "凤舞九霄",
  ["illustrator:zhonger_lord_heg__caocao"] = "波子",
  ["zongyu"] = "总御",
  [":zongyu"] = "锁定技，①当你使用坐骑牌时，若其他角色的装备区内或弃牌堆内有【六龙骖驾】，你将原坐骑牌置入弃牌堆，将【六龙骖驾】置入你的装备区内；"..
  "②当【六龙骖驾】移动至其他角色的装备区内后，你可交换你与其装备区内的防御坐骑牌。",
  ["jianan"] = "建安",
  [":jianan"] = "<b><font color='goldenrod'>君主技</font></b>，你拥有“五子良将纛”。<br>" ..
  "#<b>五子良将纛</b>：魏势力角色的准备阶段，其可弃置一张牌并选择一张暗置的武将牌或暗置两张已明置武将牌中的其中一张，" ..
  "若如此做，其获得〖节钺〗、〖突袭〗、〖巧变〗、〖骁果〗、〖断粮〗中一个场上没有的技能，"..
  "且不能明置以此法选择或暗置的武将牌，直至你回合开始。",
  ["huibian"] = "挥鞭",
  [":huibian"] = "出牌阶段限一次，你可选择一名魏势力角色和另一名已受伤的魏势力角色，若如此做，你对前者造成1点伤害，令其摸两张牌，然后后者回复1点体力。",
  ["#huibian-prompt"] = "挥鞭：你选择一名魏势力角色和另一名已受伤的魏势力角色",

  ["#jianan-ask"] = "五子良将纛：你可弃置一张牌，暗置一张武将牌，选择获得〖节钺〗〖突袭〗〖巧变〗〖骁果〗〖断粮〗",
  ["#jianan-choice"] = "五子良将纛：获得以下一个技能",

  ["@jianan_skills"] = "良将纛",

  ["#zongyu-ask"] = "总御：是否交换你与其装备区内的所有防御坐骑牌",

  ["jianan__ld__jieyue"] = "节钺",
  [":jianan__ld__jieyue"] = "准备阶段，你可将一张手牌交给不是魏势力或没有势力的一名角色，对其发起军令。若其：执行，你摸一张牌；不执行，摸牌阶段，你令额定摸牌数+3。",
  ["#jianan__ld__jieyue-target"] = "节钺：你可将一张手牌交给不是魏势力或没有势力的一名角色，对其发起军令",
  ["#jianan__ld__jieyue_draw"] = "节钺",

  ["jianan__ex__tuxi"] = "突袭",
  [":jianan__ex__tuxi"] = "摸牌阶段，你可以少摸任意张牌并获得等量其他角色各一张手牌。",
  ["#jianan__ex__tuxi-choose"] = "突袭：你可以少摸至多%arg张牌，获得等量其他角色各一张手牌",

  ["jianan__qiaobian"] = "巧变",
  [":jianan__qiaobian"] = "你的阶段开始前（准备阶段和结束阶段除外），你可以弃置一张手牌跳过该阶段。若以此法跳过摸牌阶段，"..
  "你可以获得至多两名其他角色的各一张手牌；若以此法跳过出牌阶段，你可以将场上的一张牌移动至另一名角色相应的区域内。",
  ["#jianan__qiaobian-invoke"] = "巧变：你可以弃一张手牌，跳过 %arg",
  ["#jianan__qiaobian-choose"] = "巧变：你可以依次获得%arg名角色的各一张手牌",
  ["#jianan__qiaobian-move"] = "巧变：请选择两名角色，移动场上的一张牌",

  ["jianan__hs__duanliang"] = "断粮",
  [":jianan__hs__duanliang"] = "你可将一张不为锦囊牌的黑色牌当【兵粮寸断】使用（无距离关系的限制），若你至目标对应的角色的距离大于2，此技能于此阶段内无效。",
  ["@@jianan__hs__duanliang-phase"] = "断粮 无效",

  ["jianan__hs__xiaoguo"] = "骁果",
  [":jianan__hs__xiaoguo"] = "其他角色的结束阶段，你可以弃置一张基本牌，然后其选择一项：1.弃置一张装备牌，然后你摸一张牌；2.你对其造成1点伤害。",
  ["#jianan__hs__xiaoguo-invoke"] = "骁果：你可以弃置一张基本牌，%dest 需弃置一张装备牌，否则你对其造成1点伤害",
  ["#jianan__hs__xiaoguo-discard"] = "骁果：你需弃置一张装备牌，否则 %src 对你造成1点伤害",

  ["$jianan1"] = "虎贲三千，堪当敌万余！",
  ["$jianan2"] = "壮士八百，足护卫吾身！",
  ["$huibian_zhonger_lord_heg__caocao1"] = "立威行严法，肃佞正国纲！",
  ["$huibian_zhonger_lord_heg__caocao2"] = "悬杖分五色，治法扬清名。",
  ["$zongyu_zhonger_lord_heg__caocao1"] = "古今英雄盛世，尽赴沧海东流。",
  ["$zongyu_zhonger_lord_heg__caocao2"] = "骖六龙行御九州，行四海路下八邦！",
  ["$jianan__ld__jieyue"] = "妇人之仁，焉能成大事？",
  ["$jianan__ex__tuxi"] = "护航保驾,执戈继前!",
  ["$jianan__qiaobian"] = "海纳百川，广纳贤士！",
  ["$jianan__hs__duanliang"] = "先替我顶住！",
  ["$jianan__hs__xiaoguo"] = "帐下诸将，谁敢应之？",
  ["~zhonger_lord_heg__caocao"] = "狐死归首丘，故乡安可忘……",
}



return extension
